首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP邮件发送,但没有收到收件箱或垃圾邮件?

PHP邮件发送,但没有收到收件箱或垃圾邮件?
EN

Stack Overflow用户
提问于 2017-02-27 09:00:55
回答 1查看 1.2K关注 0票数 0

我用PHPMailer发送了邮件,发出了成功的消息,但没有收到邮件。因为这个beahvior的调试变得非常复杂。

代码语言:javascript
复制
function mail1($your_name,$from,$subject,$message){
require 'PHPMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Set who the message is to be sent from
$mail->setFrom($from, $your_name);
//Set an alternative reply-to address
$mail->addReplyTo($from, $your_name);
//Set who the message is to be sent to
$mail->addAddress('percept.ashwini@gmail.com', 'Ashvini Lanjewar');
//Set the subject line
$mail->Subject = $subject;//'PHPMailer mail() test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->Body = $message;
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    return "Mailer Error: " . $mail->ErrorInfo;
} else {
    return "Message sent!";
}
}

注:此邮件发送代码为联系我们页面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-27 09:40:44

试试这个..。通过您宝贵的输入很容易获得邮件

代码语言:javascript
复制
    $to      = "yourname@gmail.com";
    $subject = "Subject of the Mail";

    $message = "<html><body>";
    $message .="Dear ,<br/><br/>";

    $message .= "</body></html>";


    $message .= "Dear ,". "\r\n". "Your comment added sucessfully "."\r\n";


                         $headers  = "MIME-Version: 1.0\r\n";
                         $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                             $headers .= 'From: fromid@gmail.com'."\r\n" .
                                 "Cc:".$sendlist_manager."\r\n" .
                                 'MIME-Version: 1.0'.'\r\n'.
                                 'Content-Type: text/html; charset=\"iso-8859-1\" '."\r\n".
                                  'X-Mailer: PHP/' . phpversion();


if (mail($to, $subject, $message, $headers))
{
    //Send success message.
    echo '<script type="text/javascript">alert("Mail Sent!"); </script>';

}
else
{ 
    echo '<script type="text/javascript">alert(" Mail not sent, please try again!"); </script>';    
}
?>

如果您使用Mime版本,并且内容类型更好,我想..

如果你对邮件有更详细的了解,请查看这里的https://github.com/PHPMailer/PHPMailer PHPMailer PHPMailer on Github

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42481498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档