SMTP authentication in PHP
Posted: Fri Apr 24, 2009 2:28 am
Hi,
I'm trying to send a mail through PHP script as given below:
_____________________________________________________________
<?php
require_once 'C:/xampp/php/PEAR/Mail.php';
$from = "Sender <abc.xyz@uv.com>";
$to = "Recipient <abc.xyz@uv.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.uv.com";
$port = "25";
$username = "abc xyz";
$password = "lmnop";
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
ini_set("SMTP","smtp.uv.com");
ini_set("smtp_port","25");
ini_set("sendmail_from","abc.xyz@uv.com");
$smtp = Mail::factory('smtp',array ('host' => $host,'port' => $port, 'auth' => true,'username' => $username,'password' => $password));
var_dump($smtp);
//$smtp = Mail::factory('smtp',array ('host' => $host,'auth' => true,'username' => $username,'password' => $password));
echo 'Trying to send mail....';
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
____________________________________________________________
Here are my SMTP server details:
Server name: smtp.uv.com
Port: 25
Connection type: SSL
Authorization required: YES
The above server requires SSL authentication. We need to give username and password. While sending the mail, I'm getting the following message after execution and no mail is send:
___________________________________________________________________________
object(Mail_smtp)#1 (13) { ["_smtp"]=> NULL ["_extparams"]=> array(0) { } ["host"]=> string(11) "smtp.uv.com" ["port"]=> string(2) "25" ["auth"]=> bool(true) ["username"]=> string(7) "abc xyz" ["password"]=> string(5) "lmnop" ["localhost"]=> string(9) "localhost" ["timeout"]=> NULL ["debug"]=> bool(false) ["persist"]=> bool(false) ["pipelining"]=> NULL ["sep"]=> string(2) " " } Trying to send mail....
___________________________________________________________________________
Could you please rectify my PHP script as given above for proper SSL authentication, connection and mailing?
I'll appreciate all the help.
Best Regards,
DPHP
I'm trying to send a mail through PHP script as given below:
_____________________________________________________________
<?php
require_once 'C:/xampp/php/PEAR/Mail.php';
$from = "Sender <abc.xyz@uv.com>";
$to = "Recipient <abc.xyz@uv.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.uv.com";
$port = "25";
$username = "abc xyz";
$password = "lmnop";
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
ini_set("SMTP","smtp.uv.com");
ini_set("smtp_port","25");
ini_set("sendmail_from","abc.xyz@uv.com");
$smtp = Mail::factory('smtp',array ('host' => $host,'port' => $port, 'auth' => true,'username' => $username,'password' => $password));
var_dump($smtp);
//$smtp = Mail::factory('smtp',array ('host' => $host,'auth' => true,'username' => $username,'password' => $password));
echo 'Trying to send mail....';
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
____________________________________________________________
Here are my SMTP server details:
Server name: smtp.uv.com
Port: 25
Connection type: SSL
Authorization required: YES
The above server requires SSL authentication. We need to give username and password. While sending the mail, I'm getting the following message after execution and no mail is send:
___________________________________________________________________________
object(Mail_smtp)#1 (13) { ["_smtp"]=> NULL ["_extparams"]=> array(0) { } ["host"]=> string(11) "smtp.uv.com" ["port"]=> string(2) "25" ["auth"]=> bool(true) ["username"]=> string(7) "abc xyz" ["password"]=> string(5) "lmnop" ["localhost"]=> string(9) "localhost" ["timeout"]=> NULL ["debug"]=> bool(false) ["persist"]=> bool(false) ["pipelining"]=> NULL ["sep"]=> string(2) " " } Trying to send mail....
___________________________________________________________________________
Could you please rectify my PHP script as given above for proper SSL authentication, connection and mailing?
I'll appreciate all the help.
Best Regards,
DPHP