【问题标题】:How to send email in xampp localhost using PHPmailer?如何使用 PHPmailer 在 xampp localhost 中发送电子邮件?
【发布时间】:2018-10-16 20:44:38
【问题描述】:

我附上了两个不同的 PDF 文件(mnlocalXampprnlocalXampp),它们是两台不同电脑的 phpinfo。我检查了这两个信息,似乎两者都有相同的信息并使用相同版本的 PHP,但我在 mnlocalXampp 中收到电子邮件,但在 rnlocalXampp 中没有。我还在两者中都激活了 openssl,但我仍然没有在 rnlocalxampp 中收到电子邮件。任何人都可以看看这两个文件,让我知道这些文件有什么区别以及如何配置。

<?php
 require 'email_class/class.phpmailer.php';
 $mail = new PHPMailer;
 $mail->IsSMTP();          //Sets Mailer to send message using SMTP
 $mail->Host = 'cp-in-10.webhostbox.net';    //Sets the SMTP hosts of your Email hosting, this for Godaddy
 $mail->Port = '465';                //Sets the default SMTP server port
 $mail->SMTPAuth = true;       //Sets SMTP authentication. Utilizes the Username and Password variables
 $mail->Username = 'mn@infotech.com';    //Sets SMTP username
 $mail->Password = 'xxxxxxx';          //Sets SMTP password
 $mail->SMTPSecure = 'ssl';          //Sets connection prefix. Options are "", "ssl" or "tls"
 $mail->From = 'mn@infotech.com';          //Sets the From email address for the message
 $mail->FromName = "mn";        //Sets the From name of the message
 $mail->AddAddress("m@infotech.com");    //Adds a "To" address
 $mail->AddCC("m@infotech.com");  //Adds a "Cc" address
 $mail->WordWrap = 50;       //Sets word wrapping on the body of the message to a given number of characters
 $headers = "MIME-Version: 1.0" . "\r\n";
 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
 $mail->IsHTML(true);              //Sets message type to HTML       
 $mail->Subject = 'Project CMS';       //Sets the Subject of the message
 $mail->Body = $message; //An HTML or plain text message body
 $mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf'); 
 $mail->Send(); ?>

以上示例代码是mnlocaXampp的邮件配置。对于 rnlocalXampp,我使用不同的端口(端口号:25)、托管、启用 SSL。

mnlocalXampp

rnlocalXampp

提前致谢

【问题讨论】:

    标签: xampp phpmailer phpinfo


    【解决方案1】:

    很难知道从哪里开始。

    您的代码基于一个过时的示例,并且您使用的是旧版本的 PHPMailer,因此 get the latest,并且您的代码基于提供的示例。

    您没有在使用之前定义$doc

    addStringAttachment 是在您尝试发送本地文件时使用的错误方法;请改用addAttachment

    $headers 的定义毫无意义。

    抄送你已经发送到的地址是没有意义的。

    您在任何地方都没有错误检查。

    解决上述部分问题可能有助于解决您的问题。

    【讨论】:

    • 感谢您的回复。您能否检查一下我附上的两个 phpinfo 文档的链接(mnlocalXampprnlocalXampp。实际上我的代码没有错误,而且我也在使用最新版本的 PHPmailer。问题是我在一个本地主机 (mnlocalXampp) 中收到电子邮件,而在另一个我没有收到邮件,即我的客户端 (rnlocalXampp) 电脑。我认为他们可能使用代理,这就是为什么我的客户端电脑没有发送电子邮件。
    • 没有。您需要在问题中包含所有相关信息。当您的代码中有基本错误时,查看您的 PHP 配置是没有意义的。你没有使用最新的PHPMailer;最新版本不会与您的代码一起运行。
    猜你喜欢
    • 2012-05-07
    • 2016-12-11
    • 2018-03-08
    • 2018-08-02
    • 2016-05-13
    • 2018-05-16
    • 2018-02-24
    • 1970-01-01
    相关资源
    最近更新 更多