简体   繁体   English

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

[英]xampp - Do I need to change php.ini and sendmail.ini to send emails with phpMailer?

When I click on submit button 当我点击提交按钮

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

It should send an email to the registered user 它应该发送电子邮件给注册用户

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;

But it doesn't work. 但这是行不通的。 I found people on the internet changing some php.ini and sendmail.ini codes. 我发现互联网上的人们在更改一些php.inisendmail.ini代码。 Am I supposed to do that? 我应该这样做吗?

No. You are using PHPMailer's SMTP client class, which is generally not affected by ini file settings. 否。您正在使用PHPMailer的SMTP客户端类,该类通常不受ini文件设置的影响。

It's not clear if this is all your code, but you don't have a call to the send method in what you have posted. 尚不清楚这是否就是您的全部代码,但是您在所发布的内容中没有调用send方法。 That would certainly stop it from sending. 那肯定会阻止它发送。

If it's not those things, I recommend following the troubleshooting guide and searching on here - just about everything to do with PHPMailer has been asked here before! 如果不是这些,我建议您遵循故障排除指南并在此处进行搜索-之前几乎已询问与PHPMailer有关的所有事项!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM