【问题标题】:How to test email from ubuntu localhost如何测试来自 ubuntu localhost 的电子邮件
【发布时间】:2015-06-22 11:48:22
【问题描述】:

我正在用 PHP 开发电子邮件队列应用程序,我想测试邮件是否发送正确。据我所知,我知道以下方法

  1. 发送邮件。
  2. 后缀。

但这些方法需要 SMTP。有没有其他方法可以做到这一点?

【问题讨论】:

    标签: php smtp localhost ubuntu-14.04


    【解决方案1】:

    您可以使用 phpmailer 类。 PHPMailer是个不错的选择

    <?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 - " . $mail->ErrorInfo;
    }
    
    ?>
    

    phpmailer class

    【讨论】:

    • 谢谢你的回答,但这有 PHP Mailer 的依赖,而且它正在发送实际的邮件。我更喜欢只显示邮件在发送时的样子的方法。
    猜你喜欢
    • 2015-07-09
    • 1970-01-01
    • 2015-06-13
    • 2022-11-17
    • 2015-07-31
    • 2019-11-23
    • 2011-10-10
    • 1970-01-01
    • 2011-05-26
    相关资源
    最近更新 更多