2015-10-21 83 views
-1

但是當我提交執行文件時,郵件不會發送到我的Gmail。使用gmail xampp發送php郵件不工作

我已經在xampp中更改了php.ini,其中sendmail_path不以「;」開頭。

在sendemail.ini中,我也將smtpp_server更改爲smtp.gmail.com。以及smtp端口587(也嘗試過465)。最後,我將auth_username和auth_password更改爲我的電子郵件和密碼。但代碼仍然不起作用。

我使用Windows 8

<?php 
mail('[email protected]', 'sample mail', 'sample content', 'From: [email protected]'); 
?> 

回答

0

您應該配置由以下sendmail.ini,如果你想從本地主機發送郵件。

您可以使用sendmail包,sendmail從localhost發送郵件 包在XAMPP中是inbuild。因此,如果您使用XAMPP,那麼您可以從本地主機輕鬆發送郵件 。

例如你可以配置C:\xampp\php\php.inic:\xampp\sendmail\sendmail.ini讓gmail發送郵件。在 C:\xampp\php\php.ini找到extension=php_openssl.dll並從該行的開頭刪除 分號以使SSL爲 gmail for localhost工作。

在php.ini文件中找到[mail function]和改變

SMTP=smtp.gmail.com 
smtp_port=587 
sendmail_from = [email protected] 
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 

現在打開C:\xampp\sendmail\sendmail.ini。在sendmail.ini替換所有現有 代碼與下面的代碼

[sendmail] 

smtp_server=smtp.gmail.com 
smtp_port=587 
error_logfile=error.log 
debug_logfile=debug.log 
[email protected] 
auth_password=my-gmail-password 
[email protected] 

現在你已經做了!使用郵件功能創建php文件,並從本地主機發送郵件 。

PS:不要忘了更換我的Gmail郵箱-ID在上面的代碼我的Gmail郵箱密碼 。另外,如果您從上面複製設置,請不要忘記刪除重複密鑰。對於下面如果 行示例評論還有另外一個sendmail_pathsendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"在php.ini文件

還記得使用XAMMP控制面板,使 更改生效重新啓動服務器。

+0

喜後,我執行與郵件功能的PHP文件。郵件在xampp的郵件輸出文件夾中結束。你知道如何解決這個問題嗎? –

0

應該配置SMTP。 C:\xampp\sendmail\sendmail.iniC:\xampp\php\php.ini

此外,您還可以使用PHPMailer容易:

<?php 
require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

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

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
}