【问题标题】:how to send mail to wamp server?如何将邮件发送到 wamp 服务器?
【发布时间】:2015-01-06 08:54:19
【问题描述】:
<?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 testing message sendmail.exe subject


    【解决方案1】:

    您需要在 localhost 上配置 SMTP 以发送电子邮件

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

    [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
    

    更多信息:- WAMP send Mail using SMTP localhost

    【讨论】:

    • [邮件功能] ; XAMPP:如果您想使用像 Mercury SMTP = mail.host.com smtp_port = 25 这样的 SMTP 服务器,请将此注释掉;仅适用于 Win32。 ; php.net/sendmail-from sendmail_from = postmaster@localhost 这个编码是对还是错??
    • 你需要设置你的邮件服务器主机 SMTP = mail.host.com
    【解决方案2】:

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

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

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

    3)安装邮件包

    4)安装net_smtp包

    示例邮件脚本:

    $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>');
    }
    ?>
    

    【讨论】:

    • 如何获取 pear 安装程序?有没有可用的链接??
    • Pear-pear.php.net/manual/en/installation.getting.php 按照上述页面设置环境变量的给定指令安装 pear。运行命令 pear install mail package pear install net_smtp package 然后运行上面的脚本。很有趣,试试吧。
    【解决方案3】:

    有两种发送电子邮件的方式。 SMTP或php邮件功能。根据您的代码,您使用的是php邮件功能。

    区别:

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

    php 邮件功能使用您自己的邮件传输代理 (MTA)。

    邮件传输代理 (MTA) 是一种软件,例如 Linux 中的 sendmail。在 Windows 上设置 MTA 并不容易。如果你只需要调试邮件的输出内容,建议你使用这个工具,Test Mail Server Tool

    【讨论】:

      猜你喜欢
      • 2013-12-19
      • 2011-08-12
      • 1970-01-01
      • 2019-06-01
      • 2011-12-10
      • 2013-11-21
      • 2014-04-19
      • 2015-09-05
      • 2013-11-11
      相关资源
      最近更新 更多