douzhaochan6468 2013-04-02 02:34
浏览 42

PHP将邮件发送给1到10个收件人

I am sure I am overlooking something here, all other mail scripts are working fine except this one. I have an HTML form which collects up to 10 email addresses. all I need to do it to iterate through them and if they are filled, send email to the recipient.

$email0 = 'email@email.com';
$email1 = 'some@email1.com';
$email2 = 'some@email2.com';
$email3 = 'some@email3.com';
$email4 = 'some@email4.com';
....... up to 10.

$i=1;
while($i<=10)
{
    $temp = 'email'.$i;
    if(isset($$temp) && $$temp != '')
    {               
        $subject="some subject";
        $body = "email content";

        $headers = "From: $email0 
";
        $headers .= "Reply-To: $email0 
";
        mail($$temp, $subject, $body, $headers);        
    }

$i++;
}

...OK I just tried a different way. I stuffed all the emails in one array and iterated through it. The same result, no emails received!!!! What am I missing ? :)

$recipients = array($email1,$email2,$email3,$email4,$email5,$email6,$email7,$email8,$email9,$email10);

foreach($recipients as $value)
{
        if($value != '')
        {   
            $subject2="some subject";
            $body2 = "some content";

            $headers2 = "From: $email0 
";
            $headers2 .= "Reply-To: $email0 
";
            mail($value, $subject2, $body2, $headers2);
        }

}

At this point I am going to post the following:

  • It just so happened that all my previous attempts started to come into may spam box (several hours latter!). So my suspicion seems to be confirmed: when on GoDaddy shared hosting do not send more than one email at the same time in short intervals (with the same content) or it will end up labeled as spam!

SOLUTION:

As jmbertucci in the posts below suggested, the simplest solution is to use BCC: for all the recipients in one email. Since I had to personalize each email, I noticed that if I include the unique char. into the subject line for each email, it goes through with no problem as well. So my solution is adding the recipients' name into the subject line (which makes all emails unique) but any unique string should do the same (like date() etc.)

  • 写回答

1条回答 默认 最新

  • doupuchen6378 2013-04-02 03:01
    关注

    Did u try to check if your mail server is properly config or config it like this sample

    // Please specify your Mail Server - Example: mail.example.com.
    ini_set("SMTP","mail.example.com");
    
    // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
    ini_set("smtp_port","25");
    
    // Please specify the return address to use
    ini_set('sendmail_from', 'example@YourDomain.com')
    ;
    

    or check you php.ini file for this. heres a sample config.

    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    ; For Win32 only.
    ;sendmail_from = me@example.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?