xampp - 我是否需要更改php.ini和sendmail.ini以使用phpMailer发送电子邮件?

时间:2017-03-28 18:45:49

标签: php xampp smtp localhost phpmailer

点击提交按钮

if (isset($_POST['btn_signup'])) {...

应该向注册用户发送电子邮件

require './PHPMailer/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->isSMTP();                            // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';             // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                     // Enable SMTP authentication
    $mail->Username = 'myEmail@gmail.com'; // SMTP username
    $mail->Password = 'myPassword';            // SMTP password
    $mail->SMTPSecure = 'tls';                  // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                          // TCP port to connect to

    $mail->setFrom('myEmail@gmail.com', 'Admin');
    $mail->addAddress($_POST['email']);   // Add a recipient
    //$mail->addReplyTo('info@phpmailer.com', 'phpmailer');
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    $mail->isHTML(true);  // Set email format to HTML

    $bodyContent = '<h1>How to Send Email using PHP in Localhost</h1>';
    $bodyContent .= '<p>This is the HTML email sent from localhost using PHP</p>';

    $mail->Subject = 'Email from Localhost';
    $mail->Body    = $bodyContent;

但它不起作用。我发现互联网上的用户更改了一些php.inisendmail.ini代码。我应该这样做吗?

1 个答案:

答案 0 :(得分:0)

没有。您正在使用PHPMailer的SMTP客户端类,它通常不受ini文件设置的影响。

目前尚不清楚这是否是您的所有代码,但您没有在已发布的内容中调用send方法。这肯定会阻止它发送。

如果不是那些东西,我建议您按照故障排除指南进行搜索 - 这里有关于PHPMailer的所有事情之前的问题!