views:

52

answers:

2

I am writing the Mail Module in my project and decide to use phpmailer to send the test email to my gmail account. However, I end up with the following error msg.

SMTP server error: "Your IP: 221.253.178.1 : Your domain myserver.com is not allowed in 550 header From"

My codes are as follow:

<?php

require_once('phpMailer/class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = "Hello World";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth   = true;                 // enable SMTP authentication
$mail->Host       = "mail.myserver.com";  // sets SMTP server
$mail->Username   = "ttcg+myserver.com";  // username
$mail->Password   = "xxxxx";              // password
$mail->Port       = 26;           // sets PORT

$mail->SetFrom('[email protected]', 'ttcg');

$address = "[email protected]";
$mail->AddAddress($address, "TTCG");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->MsgHTML($body);

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

?>

Can someone help me with this? Thanks.

A: 

I am sure there are multiple ways to set this up, but I see your code is significantly different from what I use. Maybe you can try this and see if it gives you better results I am using PHP 5 by the way, not sure if you are using a different version or not:

     require_once "Mail.php";
     $from = "you <[email protected]>";
     $subject = "message_subject";
     $body = "message_body";
     $host = "ssl://smtp.gmail.com";
     $port = "465";
     $username = "[email protected]";
     $password = "server_password"; //this is a LAMP server

     $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
     $smtp = Mail::factory('smtp', array('host' => $host, 'port'=> $port, 'auth' => true, 'username' => $username, 'password' => $password));
     $mail = $smtp->send($to, $headers, $body);//Some obvious variables
     if(PEAR::isError($mail))
     {
             echo("<p>" . $mail->getMessage() . "</p>");

     } 
     else
     {
             header("Location: Success.php");//Redirect page for success
     }
typoknig
A: 
Kwasi Owusu Gyasi-Agyei