这是我的代码
$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";
}
如果我执行上面的代码,我甚至没有收到任何邮件。邮件也没有收到。
如果我在cc中使用一个邮件地址,我会收到邮件,但是' To'邮件未收到
任何人都可以帮我吗?
答案 0 :(得分: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';
}
?>