简体   繁体   English

SMTP无法在WAMP服务器上运行

[英]SMTP Not Working on WAMP Server

I have installed WAMP Server on my Windows 10 PC and when I try to send emails through a valid SMTP configuration it doesn't work. 我在Windows 10 PC上安装了WAMP Server,当我尝试通过有效的SMTP配置发送电子邮件时,它不起作用。 The same SMTP configuration works on another LAMP installation and also on a live server. 相同的SMTP配置适用于另一个LAMP安装以及实时服务器。

When I try sending the email through a PrestaShop installation I get following error: 当我尝试通过PrestaShop安装发送电子邮件时,我收到以下错误:

Error: Please check your configuration
Connection could not be established with host smtp.gmail.com [ #0]

And with Magento I get following error: 随着Magento我得到以下错误:

SMTP Pro Self Test Results
Sending test email to your contact form address: xxxxxxx@example.com from: xxx.adsxx@example.com. Unable to send test email.
Exception message was: Could not open socket
Please check the user guide for frequent error messages and their solutions.
Default templates exist.
Email communications are enabled.

As per my understanding, this issue is not dependent on Magento or PrestaShop, it is coming because of the WAMP installation. 根据我的理解,这个问题不依赖于Magento或PrestaShop,它是因为WAMP安装而来的。

Do I have to enable some extension or something for the WAMP installation? 我是否必须为WAMP安装启用某些扩展或其他内容? Or have I missed something else? 还是我错过了别的什么?

Please help. 请帮忙。 Already wasted a lot of time investigating and trying solutions from the Web, but nothing seems to be working. 已经浪费了大量时间从Web上调查和尝试解决方案,但似乎没有任何工作。

These are possibly causes which prevent you from sending mails via WAMP server. 这些可能是阻止您通过WAMP服务器发送邮件的原因。

  • Your firewall configurations may (by default) block some ports used by WAMP for sending emails. 您的防火墙配置可能(默认情况下)阻止WAMP用于发送电子邮件的某些端口。
  • These ports may be already used by your others applications . 这些端口可能已被您的其他应用程序使用 Prefer to this to know which port is being used by which application. 不想这一要知道正在使用哪个端口,通过该应用程序。
  • Administrators rights are required for the WAMP server to be able to send mail. WAMP服务器需要管理员权限才能发送邮件。 Run the server as administrator. 以管理员身份运行服务器。

Since you're sure that settings have already worked on a server so I assume there nothing to check with PHP.ini 既然您确定设置已经在服务器上运行,那么我假设没有什么可以检查PHP.ini

Download the sendmail.zip 下载sendmail.zip

Create a folder named “sendmail” in “C:\\wamp\\”. 在“C:\\ wamp \\”中创建名为“sendmail”的文件夹。 Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”. 在“sendmail”文件夹中解压缩这4个文件:“sendmail.exe”,“libeay32.dll”,“ssleay32.dll”和“sendmail.ini”。 Open the “sendmail.ini” file and configure it as following 打开“sendmail.ini”文件并将其配置如下

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

You do not need to specify any value for these properties: pop3_server, pop3_username, pop3_password, force_sender, force_recipient. 您无需为这些属性指定任何值:pop3_server,pop3_username,pop3_password,force_sender,force_recipient。 The error_logfile and debug_logfile settings should be kept blank if you have already sent successful email(s) otherwise size of this file will keep increasing. 如果您已经发送了成功的电子邮件,则error_logfile和debug_logfile设置应保持空白,否则此文件的大小将不断增加。 Enable these log file settings if you don't get able to send email using sendmail. 如果您无法使用sendmail发送电子邮件,请启用这些日志文件设置。

Enable IMAP Access in your GMail's Settings -> Forwarding and POP/IMAP -> IMAP Access: 在您的GMail设置中启用IMAP访问 - >转发和POP / IMAP - > IMAP访问:

Enable “php_openssl” and “php_sockets” extensions for PHP compiler:

Open php.ini from “C:\wamp\bin\apache\Apache2.2.17\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work) (You just need to configure the last line in the following code, prefix semicolon (;) against other lines):

Restart WAMP Server. 重启WAMP服务器。 Create a PHP file and write the following code in it: 创建一个PHP文件并在其中编写以下代码:

<?php
$to       = 'recipient@yahoo.com';
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: [your_gmail_account_username]@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
    echo "Email sent";
else
    echo "Email sending failed";
?>

Make appropriate changes in $to and $headers variables to set recipient and sender (“From” header) addresses. 在$ to和$ headers变量中进行适当的更改以设置收件人和发件人(“From”标头)地址。 Save it as “send-mail.php”. 将其另存为“send-mail.php”。 (You can save it anywhere or inside any sub-folder in “C:\\wamp\\www”.) Open this file in browser, it MUST work now (您可以将它保存在“C:\\ wamp \\ www”中的任何子文件夹中。)在浏览器中打开此文件,它必须立即工作

  1. make sure that your - 确保你的 -

      extension=php_openssl.dll extension=php_sockets.dll 

is enable in php.ini file. 在php.ini文件中启用。

  1. check is Enable ssl_module under Apache Module. check是在Apache Module下启用ssl_module。

You can use PHP Mailer or Download php mailer with example from here . 您可以使用PHP Mailer从这里下载php mailer。 Once you setup the phpmailer with your project use following code to send mail using gmail SMTP : 在您的项目中设置phpmailer后,使用以下代码使用gmail SMTP发送邮件:

require_once('inc/class.phpmailer.php');        # INCLUDE PHPMailer CLASS FILE
require_once("inc/class.smtp.php");                 # INCLUDE OTHER SMTP FILE

Include above files in your project or PHP file which you use to send email and then : 在项目中包含上述文件或用于发送电子邮件的PHP文件,然后:

$mail             = new PHPMailer();

$mail->IsSMTP(); 
$mail->SMTPDebug  = 0;                      # ENABLE SMTP DEBUG INFORMATION (FOR TESTING)
                                            # 1 = ERROR AND MESSAGE
                                            # 2 = MESSAGE ONLY
$mail->SMTPAuth   = true;                   # ENABLE SMTP AUTHENTICATION
$mail->Host       = "Host Addresss";        # smtp.gmail.com
$mail->Port       = 587;                    # PORT NUMBER
$mail->Username   = "example@gmail.com";        # SMTP EMAIL USER NAME
$mail->Password   = "xxxxxxx";          # SMTP ACCOUNT PASSWORD
$mail->SetFrom('example@gmail.com', 'Test Name');
$mail->SMTPSecure = 'tls';
$mail->AddReplyTo("example@gmail.com","SMTP TEST");
$v_Msg ="This is a test message via SMTP";

$mail->Subject    = "EMAIL SUBJECT";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; # OPTIONAL
$address = "sendto@email.com";          # ADDRESS WHERE YOU WANT TO SEND MAIL
$mail->AddAddress($address, "TESTING");
$mail->MsgHTML($v_Msg);                 # EMAIL CONTENT

if(!$mail->Send()) {                    
    echo "Mailer Error: " . $mail->ErrorInfo;   # ERROR MESSAGE, IF MAIL NOT SENT SUCCESSFULLY 
}else {
    echo "Message sent!";               # SUCCESS MESSAGE
}

NOTE : Make sure your smtp gmail account must be Allow less secure apps: ON . 注意 :确保您的smtp gmail帐户必须是Allow less secure apps: ON You can turn on less secure apps for your gmail account using THIS URL 您可以使用此网址为您的Gmail帐户启用安全性较低的应用

Sometimes its easier not to rely on your own smtp server. 有时它更容易不依赖于您自己的smtp服务器。 (firewalls everywhere) (到处都是防火墙)

You can experiment with some other online mail delivery services than gmail, like mailgun or sendgrid . 您可以尝试使用除邮件之外的其他在线邮件传递服务,例如mailgunsendgrid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM