phpMailer与smtp

时间:2011-03-04 11:51:08

标签: phpmailer

我有这段代码:

    ini_set('SMTP','smtp.strato.com');
$mail = new PHPmailer();
$mail->IsHTML(true);

它工作正常,但我可以在phpMailer类中的某处设置smtp.strato.com吗?

3 个答案:

答案 0 :(得分:4)

您是否查看了其网站中的smtp示例? See here

除非我不理解你,否则它看起来非常直接。

$mail             = new PHPMailer();

$body             = "message";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);

$mail->AddAddress("whoto@otherdomain.com", "John Doe");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

答案 1 :(得分:0)

您可以通过更改

    $mail->IsSMTP(); 
    $mail->Host       = "mail.yourdomain.com"; 

    $mail->IsSMTP(); 
    $mail->Host       = "smtp.strato.com"; 

你不应该修改PHPMailer类

答案 2 :(得分:0)

//Use this codd to send email using SMTP gmail    
<?php
require "PHPMailer/PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth="login";
$mail->SMTPSecure="ssl";
$mail->Username = "sender@gmail.com";
$mail->Password="password";
$mail->Body="<Body message>";
$mail->MsgHTML=("<h1>Wow Html contents</h1>");
$mail->AddAttachment("Koala.jpg");
$mail->SetFrom("sender@gmail.com","Bucky");
$mail->Subject="My Subject";
$mail->AddAddress("receiver@gmail.com");

if ($mail->Send()){
    echo "Sent";
}else 
    echo "not sent<br>";
    echo $mail->ErrorInfo;

?>