开发者

Problem while sending email in php

I am facing a strange error when I execute a php mail script. Its related to server could not verify the sender. I see following error:

Failed to add recipient email@domain.com [SMTP: Invalid response code received from server (code:550, response: Verification failed for unrouteable address Sendor verify failed)]

Would you know why this error could pop up?

 <?php
require_once "Mail.php";
$kw = (string)$_GET['keyword'];
$e = (string)$_GET['emailid'];
$uname="xxx";
$password="xxx";
$con=mysql_connect("Localhost","root","");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mysql_db",$con);

 mysql_query("INSERT INTO mail_alert       (uname,emailid,password,keyword)values('$kw','$e','$uname','$password')");



 $from = "mail.domain.com";
 $to = $e;
 $subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://domain.com";
$port="465";
$username = "login";
$password = "xxx";

$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);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}


 mysql_clo开发者_如何学Cse($con);

?>


What you are doing here is trying to send an email as you were an owner/user of the domain.com.

If you want to send an email via PHP, you must provide valid credentials of some email server. You can create mail server by yourself on your machine but it requires some effort. Well, in UNIXes it's easier, on Windows you have to download some software like hMailServer.

So, create a Gmail.com account, and here you have configuration data to set in your script (SMTP address, port number; user name and password are the Gmail's account ones).

SMTP: smtp.gmail.com
Port for TLS/STARTTLS: 587
Port for SSL: 465 
User name: your Gmail email address
Password: your Gmail password

This example might be helpful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜