XAMPP发送邮件不工作PHP

时间:2016-07-12 07:11:29

标签: php sendmail.exe

这里有详细信息

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

3 个答案:

答案 0 :(得分:0)

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

不要忘记更改虚拟值

答案 1 :(得分:0)

您必须在服务器上配置SMTP

您可以使用googles免费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发送邮件,在XAMPP中建立sendmail包。因此,如果您正在使用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');

答案 2 :(得分:0)

的php.ini

edd_get_discount_amount

为我工作。