Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
900 views
in Technique[技术] by (71.8m points)

php - How to use phpMailer isSMTP on Bluehost?

It's taken me days to get the right settings so I thought I would post a php script that works on Bluehost. In initial tests using isSMTP is faster than isMAIL.

<?php
require_once '../includes/phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->IsSMTP();                         // set mailer to use SMTP
$mail->Host = "box1311.bluehost.com";    // specify bluehost as outgoing server
$mail->SMTPSecure = "tls";               // sets the prefix to the server do not use ssl
$mail->SMTPDebug  = 3;                   // comment out if you don't need debug info
$mail->SMTPAuth   = true;                // turn on SMTP authentication
$mail->Username   = "USER@EXAMPLE.COM";  // SMTP username (your email account)
$mail->Password   = "PASSWORD";          // SMTP password
$mail->Port       = 25;
$mail->From       = 'USER@EXAMPLE.COM';
$mail->FromName   = "USER@EXAMPLE.COM";
$mail->AddAddress('CLIENT@gmail.com');
$mail->IsHTML(true);                     // set email format to HTML

$mail->Subject = 'test message';
$body = '<!DOCTYPE html>
           <html><header>
                 </header>
                 <body lang=EN-US>
                    <div style="text-align:center">
                      <h2>this is a test</h2>
                    </div>
                 </body>
            </html>';
$mail->Body    = $body;

$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send()){
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
}else{
  echo '<h1>message sent</h1>';
}
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code work for me.

include "phpmailer/class.phpmailer.php";
include "phpmailer/class.smtp.php";

$email_user = "email@host.com";
$email_password = "pass123";
$the_subject = "Title";
$from_name = "Sender";
$phpmailer = new PHPMailer();

// ---------- datos de la cuenta de correo -----------------------------
$phpmailer->Username = $email_user;
$phpmailer->Password = $email_password; 
//---------------------------------------------------------------------
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Host = "box6171.bluehost.com";
$phpmailer->Port = 26;
//$phpmailer->SMTPDebug = 2;
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true;

$phpmailer->setFrom($phpmailer->Username,$from_name);
$phpmailer->AddAddress("to@host.com");
$phpmailer->Subject = $the_subject; 

$phpmailer->Body .="<h1 style='color:#3498db;'>Attachment:</h1>";
$phpmailer->Body .= "<h3>".$attach1."</h3>";

$phpmailer->AddAttachment($attach, "attach1");
$phpmailer->AddBCC("hidecopy@host.com", "bcc1");
$phpmailer->IsHTML(true);
$enviado = $phpmailer->Send();
if($enviado) {
    echo 'email send successful';
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...