【问题标题】:How to add multiple mail address in cc php mail如何在cc php邮件中添加多个邮件地址
【发布时间】:2016-12-23 00:36:31
【问题描述】:

这是我的代码

$form_message .= "Application_Comments" . "\r\n";
ini_set('your_email', 'testsupport@example.com');
$to = "xyz@gmail.com";
$subject = "Collaboration";
$your_email = 'testsupport@example.com';
$headers  = "From: $your_email" . "\r\n";
$headers .= "Cc:abc@yahoo.com,efg@gmail.com"."\r\n";
$headers .= "Reply-To: $your_email" . "\r\n";

if(mail($to,$subject,$form_message,$headers))
{
    echo " Delete Mail Sent Successfully";
}
else
{
    echo "Delete Mail not sent";
}

如果我执行上述代码,即使“收件人”邮件也没有收到,我也不会收到任何邮件。

如果我在抄送中使用一个邮件地址,我会收到邮件,但没有收到“收件人”邮件

谁能帮我解决这个问题?

【问题讨论】:

  • This 可能有用吗?
  • ini_set('your_email', 'foo@example.com') 是干什么用的?
  • 可能是 gmail 地址拒绝该邮件或将其识别为垃圾邮件?检查您的邮件日志。
  • @Progrock 如果我将 cc 放在标头中,如果没有 cc,邮件仍然可以正常接收,但我只能添加一个。
  • 再一次,ini_set 行是干什么用的?你检查过你的邮件日志吗?

标签: php


【解决方案1】:

您应该考虑使用流行的PHPMailer 类来处理 PHP 中的电子邮件需求。它可以轻松实现发送具有多个 TO、CC、BCC 和 REPLY-TO 的电子邮件。它甚至可以让您轻松地将附件添加到您的电子邮件中。从 Github 下载 ZIP,并将其解压缩到将要使用的目录。

<?php
require '/path/to/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

【讨论】:

  • 无论多么相关,“改用这个插件”的声明并不能真正回答有关原生 PHP 函数的基本问题。 PHPMailer 很棒,但它是一个附加的插件,因此本使用它的指南对解决最初提出的问题没有任何帮助。 (不,我没有投票给你)
  • 我会支持你。每个人都应该真正停止使用 php mail() 函数。
  • 如果这有帮助,请选择作为答案。我很欣赏详细的答复。下次我会以不同的方式回答问题。 @Martin 我也完全同意尼克的观点。
  • @JoshuaWhalen 试图弯曲 OP 的手臂以接受这个作为答案是可笑的。
  • 很高兴你觉得它很幽默。 @Progrock
猜你喜欢
  • 2016-07-09
  • 1970-01-01
  • 2014-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-11
相关资源
最近更新 更多