Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何向wamp服务器发送邮件?_Php_Testing_Message_Sendmail.exe_Subject - Fatal编程技术网

Php 如何向wamp服务器发送邮件?

Php 如何向wamp服务器发送邮件?,php,testing,message,sendmail.exe,subject,Php,Testing,Message,Sendmail.exe,Subject,这是我的编码..但输出为消息发送失败。。那么我能做什么呢?您需要在本地主机上配置SMTP以发送电子邮件 转到php.ini并设置以下设置 <?php $to = 'mass.mari06@gmail.com'; $subject = 'Testing sendmail.exe'; $message = 'Hi, you just received an email using sendmail!'; $headers = 'From: sender@gmail.com'

这是我的编码..但输出为消息发送失败。。那么我能做什么呢?

您需要在本地主机上配置SMTP以发送电子邮件

转到php.ini并设置以下设置

<?php
$to       = 'mass.mari06@gmail.com';
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: sender@gmail.com' . "\r\n" .
            'Reply-To: sender@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
    echo "Email sent";
else
    echo "Email sending failed";
?>

更多信息:-

用php发送邮件的正确方法是通过pear邮件扩展。

然后,您可以按照以下步骤操作: 1安装pear:单击php文件夹中的pear.phar或pear.bet

2设置REG.ENV,如果不起作用,请将环境变量:PHP_PEAR_PHP_BIN更改为%pathWherePhpIsInstalled/PHP.exe

3安装邮件包

4install net_smtp软件包

邮件脚本示例:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
 SMTP = mail.host.com 
 smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster@localhost

发送电子邮件有两种方式。SMTP或php邮件函数。根据您的代码,您正在使用php邮件函数

区别:

SMTP使用其他供应商的邮件传输代理MTA

php邮件函数使用您自己的邮件传输代理MTA


邮件传输代理MTA是一种软件,例如Linux中的sendmail。在windows上设置MTA并不容易。如果您只需要调试邮件的输出内容,我建议您使用此工具,

[mail function];XAMPP:如果您想使用Mercury SMTP=mail.host.com SMTP_port=25这样的SMTP服务器,请将此注释掉;仅适用于Win32;sendmail_from=postmaster@localhost此编码错误或错误??您需要设置邮件服务器主机SMTP=mail.host.com如何获取pear安装程序??anylink available??Pear-根据页面上的给定说明安装Pear,如上所述设置环境变量。运行命令pear install mail package pear install net_smtp package,然后运行上述脚本。很有趣,试试看。
$from = 'senderemailaddress';
$to = 'mass.mari06@gmail.com';
$subject = 'Hi,Its subject!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => 'sender_email_addreess',
    'password' => 'pass'
));

$mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}
?>