0

我一直在努力思考这个问题,但我无法得到自己的答案......

例如,当我总结所有收到电子邮件的人时,我想用逗号分隔他们,但以点结尾!

例如这段代码:

$emailnotificationmessage = "<p id='notification'>An e-mail notification has been sent to: ";
while( $record=mysql_fetch_array($checkwhotosendresult) )
{
    $mailto=$record['email'];
    $mail_ontv = $mailto;

    if (mail($mail_ontv, $onderwerp, $inhoud_mail, $headers))
    {             
        $emailnotificationmessage .= "$mail_ontv, ";
    }
    else
    {
        $emailnotificationmessage = "<p id='notification'>Error. E-mail could not be sent to the receipent.";
    }
}
$emailnotificationmessage .= "</p>";    

它返回:

An e-mail notification has been sent to: mail@mail.com, mail2@mail.com, mail3@mail.com,

那么我怎样才能以点结尾,以保持语言正确......?

编辑

我不想为此发布新问题,只是想知道如何and在最后2一封电子邮件之间放置一个?

4

3 回答 3

3

我会以不同的方式解决这个问题(很多方法可以给猫剥皮)

// create new arrays
$sentemails = $failedemails = array();

while ($record = mysql_fetch_array($checkwhotosendresult))
{
    $mailto = $record['email'];
    $mail_ontv = $mailto;

    if (mail($mail_ontv, $onderwerp, $inhoud_mail, $headers))
    {
        $sentemails[] = $mailto;
    }
    else
    {
        $failedemails[] = $mailto;
    }
}

$emailnotificationmessage = '';

if ( ! empty($sentemails))
{
    $emailnotificationmessage .= '<p>An email notification has been sent to: ' . implode(', ', $sentemails) . '.</p>';
}
if ( ! empty($failedemails))
{
    $emailnotificationmessage .= '<p>Emails could not be sent to: ' . implode(', ', $failedemails) . '.</p>';
}

这将为您提供已发送和失败的电子邮件列表,并且不会用失败的消息覆盖已发送的邮件

于 2012-12-14T09:45:03.457 回答
2

用这个

<?php
$emailnotificationmessage="An e-mail notification has been sent to: mail@mail.com, mail2@mail.com, mail3@mail.com,";
$newsentance = substr($emailnotificationmessage, 0,-1).".";    
 echo $newsentance ;
?>
于 2012-12-14T09:44:06.123 回答
1

你可以通过substr

$emailnotificationmessage = substr($emailnotificationmessage,0,-2) . ".";
于 2012-12-14T09:39:14.500 回答