3

这是详细信息

[php.ini]

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

[发送邮件.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 设置,但它仍然无法正常工作,请建议。

4

4 回答 4

2

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

为我工作。

于 2018-01-19T18:37:29.637 回答
0

您应该改用 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';
}

不要忘记更改虚拟值

于 2016-07-12T09:53:29.030 回答
0

您必须在服务器上配置 SMTP

您可以使用谷歌免费的 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 包从 localhost 发送邮件,sendmail 包在 XAMPP 中内置。因此,如果您使用的是 XAMPP,那么您可以轻松地从 localhost 发送邮件。

例如,您可以配置 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 文件中找到 [mail function] 并更改

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');
于 2016-07-12T10:07:01.013 回答
0

对于使用 Windows 和 XAMPP 的用户,您必须将文件上的反斜杠\替换为。样本值可以是/php.ini

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

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

于 2022-02-03T07:20:17.387 回答