PHP mail()只发送给单个收件人 [英] PHP mail() sending only to single recipient

查看:134
本文介绍了PHP mail()只发送给单个收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新几个非PHP相关的页面,将客户端的表单输入到PHP。然而,没有对代码客户端进行任何更改,报告没有收到电子邮件。相反,他表示只会将电子邮件发送到其中一个电子邮件,而不是全部3.可以用一个针脚指出代码有什么问题吗?

I was updating few non PHP related pages for the client which send form input over to PHP. However without making any changes to the code client reported to not getting the e-mails. Instead he said it only sends emails to one of the emails instead of all 3. Can some one pin point whats wrong with the code?

$email_to = "info@example.com, user@live.ca, user@live.ca"; 

    $email_subject = "VIP Access"."  [".date("Y-m-d @ h:m:s A")."]";

    $first_name   = $_POST["objFirstName"];
    $last_name = $_POST["objLastName"];
    $phone     = $_POST["objPhone"];
    $email_from = $_POST["objEmail"];

    $full_name = $first_name." ".$last_name;

    $message = "";

      function clean_string($string) {
        $bad = array("content-type", "bcc:", "to:", "cc:", "href");
        return str_replace($bad, "", $string);
      }


    $message .= "<html><body>\n";
    $message .= "<table rules='all' border='1' style='border-color:#000;' cellpadding='10' width='100%'>\n";
    $message .= "<tr style='background: #eee;'><td width='20%'><strong>Full Name:</strong> </td><td width='70%'>".clean_string($full_name)."</td></tr>\n";
    $message .= "<tr style='background: #eee;'><td width='20%'><strong>Email:</strong> </td><td width='70%'>".clean_string($email_from)."</td></tr>\n";
    $message .= "<tr style='background: #eee;'><td width='20%'><strong>Phone:</strong> </td><td width='70%'><a href='tel:".clean_string($phone)."'>".clean_string($phone)."</a></td></tr>\n";
    $message .= "</table>\n";
    $message .= "<img src='http://example.com/images/logo-trans.png' width='120' height='130' alt='Estate Brothers' style='text-align:center;'/>\n";
    $message .= "</body></html>\n";

    // create email headers
    $headers = "From: ".$email_from." via example.com\r\n"."Reply-To: ".$email_from."\r\n"."X-Mailer: PHP/".phpversion()."via example.com";
    $headers .= 'To: Example <info@example.com>, User <user@live.ca>, User two <usertwo@live.ca>' . "\r\n";
    $headers .= 'MIME-Version: 1.0'."\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";

    $mail_feed =  mail($email_to, $email_subject, $message, $headers);


推荐答案

在这里收购swiftmailer - > http://swiftmailer.org/

Acquite swiftmailer here -> http://swiftmailer.org/

require_once 'swiftmailer/lib/swift_required.php';

function new_mail($subject, $content)
{
    // Create the message
    $message = Swift_Message::newInstance();

    // Give the message a subject
    $message->setSubject($subject);

    // Set the From address with an associative array
    $message->setFrom(array('sender@example.com' => 'Sender')));

    // Set the To addresses with an associative array
    $message->setTo(array('info@example.com' => 'Example'));

    // Give it a body
    $message->setBody($content);

    $transport = Swift_MailTransport::newInstance();
    $mailer = Swift_Mailer::newInstance($transport);
    $result = $mailer->send($message);

}

new_mail('Subject', $messagecontentgoeshere);

如果您希望您可以用变量替换TO和FROM部分。所以你可以在网站上的任何地方重用整个功能。

If you want you can replace the TO and FROM parts with variables as well. So you can reuse the whole function everywhere on the site.

这篇关于PHP mail()只发送给单个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆