2016-08-16 150 views
0

这里是我的代码如何在CC PHP邮件添加多个邮件地址

$form_message .= "Application_Comments" . "\r\n"; 
ini_set('your_email', '[email protected]'); 
$to = "[email protected]"; 
$subject = "Collaboration"; 
$your_email = '[email protected]'; 
$headers = "From: $your_email" . "\r\n"; 
$headers .= "Cc:[email protected],[email protected]"."\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"; 
} 

如果我执行上面的代码我没有收到任何邮件,甚至“到”邮件也没有得到。

如果我使用CC我收到邮件一个邮件地址,但“收件人”邮件未收到

任何一个可以帮我在这?

+0

[这](http://stackoverflow.com/questions/14238207/php-mail-bcc-multiple-recipients)可能有用吗? – Script47

+0

什么是ini_set('your_email','[email protected]')? – Progrock

+0

难道是gmail地址拒绝邮件或将其标识为垃圾邮件?检查你的邮件日志。 – Progrock

回答

0

您应该考虑使用流行的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 = '[email protected]';     // 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('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$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'; 
} 
?> 
+0

我不明白为什么这是投下来的。 –

+0

反对的原因 – JMR

+2

不管多么相关,“使用这个插件”的声明并没有真正回答关于本地PHP函数提出的基本问题。 'PHPMailer'很棒,但它是一个附加的插件,所以这个使用它的指南对解决提出的原始问题没有任何帮助。 (不,我没有投票给你) – Martin

相关问题