doubailian4459 2014-06-12 20:03
浏览 31


I want to know how do I get a SMTP server to use PHPMailer to send automatic emails with my created email (

My webhost doesn't provide one. I brought my domain in OnlyDomains and my webhost is 000Webhost.

require './PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = '';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '';                 // SMTP username
$mail->Password = '********';                           // SMTP password
$mail->SMTPSecure = 'tls';                            
$mail->From = '';
$mail->FromName = 'Admin';
$mail->addAddress('');               // Name is optional

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'swag';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
  • 写回答

1条回答 默认 最新

  • dongnao2048 2014-06-12 20:09

    You should see if your web host allows you to use sendmail on their system. STMP is not needed with sendmail. Chances are they do since it is a standard part of most any Linux/Unix setup. And since you say that your web host is 000WebHost it seems like they do support the use of sendmail:

    You can use PHP's mail() function to send mail for your visitors…

    But they also seem to offer SMTP in their premium package.

    Past that, I would recommend not worrying about SMTP & sticking to sendmail for now. Looking at the documentation for PHPMailer it seems that the library can use sendmail:

    The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.

    Then looking in the examples/ folder in the PHPMailer repository shows there is a sendmail example:

    require '../PHPMailerAutoload.php';
    //Create a new PHPMailer instance
    $mail = new PHPMailer();
    // Set PHPMailer to use the sendmail transport
    //Set who the message is to be sent from
    $mail->setFrom('', 'First Last');
    //Set an alternative reply-to address
    $mail->addReplyTo('', 'First Last');
    //Set who the message is to be sent to
    $mail->addAddress('', 'John Doe');
    //Set the subject line
    $mail->Subject = 'PHPMailer sendmail test';
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';
    //Attach an image file
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on发生意外错误: 5无法连接到 MQTT 代理,如何解决?
  • ¥15 关于#genesiscsheel#的问题,如何解决?
  • ¥15 Android aidl for hal