2017-03-28 34 views
0

當我點擊提交按鈕xampp - 我需要更改php.ini和sendmail.ini以使用phpMailer發送電子郵件嗎?

應該發送電子郵件給註冊用戶

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 = '[email protected]'; // 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('[email protected]', 'Admin'); 
    $mail->addAddress($_POST['email']); // Add a recipient 
    //$mail->addReplyTo('[email protected]', 'phpmailer'); 
    //$mail->addCC('[email protected]'); 
    //$mail->addBCC('[email protected]'); 

    $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的代碼。我應該這樣做嗎?

回答

0

不可以。您正在使用PHPMailer的SMTP客戶端類,它通常不受ini文件設置的影響。

目前還不清楚這是否是您的所有代碼,但您沒有在發佈的內容中調用send方法。這肯定會阻止它發送。

如果不是這些東西,我建議按照故障排除指南和搜索這裏 - 關於PHPMailer的所有事情都在這裏被問到!

相關問題