使用WAMP发送电子邮件 - php

我使用最新的WAMP,当我尝试发送电子邮件时收到此消息:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\main\createaccount.php on line 8

邮件传递失败...

消息:

$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }

您还需要下载“邮件服务器”吗?

请帮忙。

参考方案

这对我有用,应该对您有用:使用Fake Sendmail和网络托管邮件服务器(即-Godaddy,1and1等)。

1.)下载sendmail zip并将其解压缩到C:\ Wamp \ bin \ sendmail(出于本示例的目的)。

2.)编辑C:\ wamp \ bin \ sendmail \ sendmail.ini并将以下内容设置为您的邮件服务器的要求(下面是我的要求):

smtp_server=mail.yourdomain.com
smtp_port=26
smtp_ssl=none
;default_domain=yourdomain.com
[email protected]
auth_password=smtppassword
;pop3_server=
;pop3_username=
;pop3_password=
;force_sender=
;force_recipient=

3.)在您的php.ini文件中设置sendmail.exe的路径。

[mail function]
; For Win32 only.
SMTP =

; For Win32 only.
sendmail_from =

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\wamp\bin\sendmail\sendmail.exe -t"

4.)重新启动Wampserver。

使用Gmail可能会成功,但是还有一些其他调整可以使它起作用。我更喜欢使用上传代码的网络主机的邮件服务器。

PHP Count数组元素 - php

嗨,有人可以解释为什么这会返回“数组由0个元素组成”。 :$arr = array(1,3,5); $count = count($arr); if ($count = 0) { echo "An array is empty."; } else { echo "An array has $count elements.…

PHP:从函数返回值并直接回显它? - php

这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html<div class="test"><?php echo get_info(); ?></div> 有没有办…

PHP-将日期插入日期时间字段 - php

我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数

PHP:将数据从二维数组复制到一维数组的最快方法 - php

我有一个巨大的二维PHP数组,带有500万行。$t = [ [ "id" => 1, "name" => "foo" ], [ "id" => 2, "name" => "bar" ] ]; 现在,我必须将此数组的I…

php-printf和sprintf具有不同的输出 - php

我编写了以下微型php程序来测试printf和sprintf:<?php $str_1 = printf("%x%x%x", 65, 127, 245); $str_2 = sprintf("%x%x%x", 65, 127, 245); echo $str_1 . "\n"; echo $s…