[英]XAMPP send mail not working PHP
這是詳細信息
[php.ini]<\/strong>
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off
您應該改用PHPMailer:從此處下載
從下載的Zip文件夾中復制PHPMailerAutoload.php並粘貼到您與我們聯系頁面的目錄中,然后將以下代碼粘貼到您的聯系頁面腳本中 :
<?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 = 'user@example.com'; // 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('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}
不要忘記更改虛擬值
您必須在服務器上配置SMTP
您可以使用Google免費的SMTP服務器,也很容易設置。
<?php
$mail = new PHPMailer(true);
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "your-gmail-account@gmail.com"; // GMAIL username
$mail->Password = "your-gmail-password"; // GMAIL password
}
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail :(";
}
?>
您也可以在下面嘗試。
您可以使用sendmail軟件包從本地發送郵件,sendmail軟件包在XAMPP中是內置的。 因此,如果您使用的是XAMPP,則可以輕松地從本地主機發送郵件。
例如,您可以將C:\\xampp\\php\\php.ini
和c:\\xampp\\sendmail\\sendmail.ini for gmail to send mail.
在C :\\xampp\\php\\php.ini find extension=php_openssl.dll
並從該行的開頭刪除分號,以使SSL適用於localhost的gmail。
在php.ini文件中找到[郵件功能]並進行更改
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = test@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Now Open C:\xampp\sendmail\sendmail.ini. Replace all the existing code in sendmail.ini with following code
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=test@gmail.com
auth_password=my-gmail-password
force_sender=test@gmail.com
//郵件功能
$mail=test@test.com
mail($mail, 'Subject', 'sample mail', 'From: test@axxx.ba');
php.ini中
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP=localhost
; http://php.net/smtp-port
;smtp_port=25
sendmail_path = C:/xampp/sendmail/sendmail.exe -t
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header=On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog
為我工作。
對於使用 Windows 和 XAMPP 的用戶,您必須在
php.ini<\/code>文件中將反斜杠
\\<\/code>替換為
\/<\/code> 。
樣本值可以是
https:\/\/dzone.com\/articles\/how-send-emails-php-windows<\/a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.