【问题标题】:xampp - Do I need to change php.ini and sendmail.ini to send emails with phpMailer?xampp - 我是否需要更改 php.ini 和 sendmail.ini 才能使用 phpMailer 发送电子邮件?
【发布时间】:2017-08-21 23:57:47
【问题描述】:

当我点击提交按钮时

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 代码。我应该这样做吗?

【问题讨论】:

    标签: php xampp smtp localhost phpmailer


    【解决方案1】:

    没有。您使用的是 PHPMailer 的 SMTP 客户端类,一般不受 ini 文件设置的影响。

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

    如果不是这些,我建议您按照故障排除指南并在此处搜索 - 之前已在此处询问过与 PHPMailer 相关的所有内容!

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 2020-07-26
      • 2013-05-22
      • 2021-09-13
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多