XAMPP 无法发送邮件 PHP

XAMPP send mail not working PHP

这是详细信息

[php.ini]

SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off

[sendmail.ini]

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
debug_logfile=debug.log
auth_username=[email]@gmail.com
auth_password=[email password]
pop3_server=
pop3_username=
pop3_password=
force_sender=[email]@gmail.com
force_recipient=
hostname=smtp.gmail.com



 [mail function]
    mail('[email]@gmail.com','sample mail','sample content','From: anotheremail@gmail.com');

我已经正确检查了 smtp 设置,但仍然无法正常工作,请提出建议。

您应该改用 PHPMailer: 从 here

下载

从下载的 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.inic:\xampp\sendmail\sendmail.ini for gmail to send mail.

在 C:\xampp\php\php.ini find extension=php_openssl.dll 中删除该行开头的分号,使 SSL 为本地主机的 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 文件中将反斜杠 \ 替换为 /。示例值可以是

sendmail_path=C:/xampp/sendmail/sendmail.exe -t -i

https://dzone.com/articles/how-send-emails-php-windows