php mail()函数不发送邮件

时间:2018-06-25 07:27:19

标签: php email variables

mail()函数无法将电子邮件发送到我的给定ID 这是我的代码:

<?php 


$to = 'abnitchauhanabnit@gmail.com';
$subject = 'Course Query';
$from = 'abnit@gmail.com';
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n".
'Reply-To: 'abnit@gmail.com"\r\n" .
'X-Mailer: PHP/' . phpversion();

// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h2>Customer Name <strong>Abc</strong></h2>';
$message .= '<h3> Phone No : <strong>Abc </strong></h3>';
$message .= '<h3> Address  : <strong>Abc</strong></h3>';
$message .= '<h3> Email  : <strong>Abc</strong></h3>';
$message .= '<h3> Date Of Birth  : <strong>Abc</strong></h3>';
$message .= '<h3> Window Version  : <strong>Abc</strong></h3>';
$message .= '<h3> Mac Address  : <strong>Abc</strong></h3>';
$message .= '<h3> Amount  : <strong>Abc</strong></h3>';
$message .= '</body></html>';

// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}


?>

消息显示为“无法发送电子邮件。请重试”。

1 个答案:

答案 0 :(得分:0)

在您的代码中,您正在使用$ email,尚未为其分配值,但是,您已从值中分配了$ e。用$ from替换$ email应该可以解决问题!