编程语言
首页 > 编程语言> > 电子邮件 – PHP无法将邮件发送到webmail

电子邮件 – PHP无法将邮件发送到webmail

作者:互联网

我在网站上有一个联系表格,如果你提交它将发送到webmail.
例如:

    $isi_pesan = $message;
    $additional_headers = "From: ".$email."" . "\r\n" . "Reply-To: $email";   
    $subject = 'Pesan untuk engineering.co.id';

    $to = 'info@engineering.co.id';
 // $to = 'dy_qie21@yahoo.com'; //this works

    if(mail($to, $subject, $isi_pesan, $additional_headers))
        echo '<div class="success-msg">Success !</div>';
    else
        echo '<div class="error-msg">Failed !</div>';

我得到的信息是“成功!”但我在收件箱webmail中什么都没有.如果$to不是webmail,则PHP邮件可以正常工作.那么我需要更改哪些设置才能使邮件在webmail中正常工作?提前致谢.

解决方法:

你看过SPAM文件夹了吗?
看看这个PHP类

https://github.com/Synchro/PHPMailer

$mail = new PHPMailer;

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->AddAddress('ellen@example.com');               // Name is optional
$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;
   exit;
}

echo 'Message has been sent';

标签:php,email,webmail
来源: https://codeday.me/bug/20190725/1534585.html