Jump to content

Send_Mail Help


ronnie88

Recommended Posts

I'm having a problem When I try to register and it sends mail I get this error:

 

 

Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\4599506\html\support\inc\functions.php on line 695

 

 

 

and here is that area of that file.

 

 

 

 

function send_mail($from, $to, $subject, $body_mail, $headers) {
require_once 'smtp.php';

$query = "SELECT * FROM support_config WHERE ID = '1'";
$req = mysql_query($query) or die("<B>Error ".mysql_errno()." :</B> ".mysql_error()."");
$row = mysql_fetch_array($req);
$to = stripslashes($to);
$smail = $row['smail'];
$host = $row['smtp_host'];
$port = $row['smtp_port'];
$user = $row['smtp_user'];
$pass = $row['smtp_pass'];
$auth = $row['smtp_auth'];
$subject = stripslashes($subject);
$body_mail = stripslashes($body_mail);
if ($smail==1){
	mail($to, $subject, $body_mail, $headers);
} else {
	$headers = $headers."To: $to\nSubject: ".$subject."\n";
	if (! ($smtp = new Net_SMTP($host,$port))) {
	    die("Unable to instantiate Net_SMTP object\n");
	}
	if (PEAR::isError($e = $smtp->connect())) {
	    die($e->getMessage() . "\n");
	}
	if ($auth==1){
		if (PEAR::isError($ea = $smtp->auth($user, $pass ))) {
		    die($ea->getMessage() . "\n");
		}
	}
	if (PEAR::isError($smtp->mailFrom($from))) {
	    die("Unable to set sender to <$from>\n");
	}
	if (PEAR::isError($res = $smtp->rcptTo($to))) {
	   die("Unable to add recipient <$to>: " . $res->getMessage() . "\n");
	}
	if (PEAR::isError($smtp->data($headers . "\r\n" . $body_mail))) {
	    die("Unable to send data\n");
	}
	$smtp->disconnect();
}
}
?>

 

 

 

Thanks,

Ronnie

Link to comment
Share on other sites

What is a bare LF, anyway?

It is an ASCII linefeed (LF) character not preceded by an ASCII carriage-return (CR) character.

 

You are using just \n in a few places (the header for one). You need to use \r\n to meet the specification for what you are doing.

Link to comment
Share on other sites

So you mean like this?:

 

function send_mail($from, $to, $subject, $body_mail, $headers) {
require_once 'smtp.php';

$query = "SELECT * FROM support_config WHERE ID = '1'";
$req = mysql_query($query) or die("<B>Error ".mysql_errno()." :</B> ".mysql_error()."");
$row = mysql_fetch_array($req);
$to = stripslashes($to);
$smail = $row['smail'];
$host = $row['smtp_host'];
$port = $row['smtp_port'];
$user = $row['smtp_user'];
$pass = $row['smtp_pass'];
$auth = $row['smtp_auth'];
$subject = stripslashes($subject);
$body_mail = stripslashes($body_mail);
if ($smail==1){
	mail($to, $subject, $body_mail, $headers);
} else {
	$headers = $headers."To: $to\r\nSubject: ".$subject."\r\n";
	if (! ($smtp = new Net_SMTP($host,$port))) {
	    die("Unable to instantiate Net_SMTP object\r\n");
	}
	if (PEAR::isError($e = $smtp->connect())) {
	    die($e->getMessage() . "\r\n");
	}
	if ($auth==1){
		if (PEAR::isError($ea = $smtp->auth($user, $pass ))) {
		    die($ea->getMessage() . "\r\n");
		}
	}
	if (PEAR::isError($smtp->mailFrom($from))) {
	    die("Unable to set sender to <$from>\r\n");
	}
	if (PEAR::isError($res = $smtp->rcptTo($to))) {
	   die("Unable to add recipient <$to>: " . $res->getMessage() . "\r\n");
	}
	if (PEAR::isError($smtp->data($headers . "\r\n" . $body_mail))) {
	    die("Unable to send data\r\n");
	}
	$smtp->disconnect();
}
}
?>

 

 

It still doesnt work like this :(

 

Thanks,

Ronnie

Link to comment
Share on other sites

it still gives me the error:

function send_mail($from, $to, $subject, $body_mail, $headers) {

  require_once 'smtp.php';

 

  $query = "SELECT * FROM support_config WHERE ID = '1'";

  $req = mysql_query($query) or die("<B>Error ".mysql_errno()." :</B> ".mysql_error()."");

  $row = mysql_fetch_array($req);

  $to = stripslashes($to);

  $smail = $row['smail'];

  $host = $row['smtp_host'];

  $port = $row['smtp_port'];

  $user = $row['smtp_user'];

  $pass = $row['smtp_pass'];

  $auth = $row['smtp_auth'];

  $subject = stripslashes($subject);

  $body_mail = stripslashes($body_mail);

  if ($smail==1){

      mail($to, $subject, $body_mail, $headers);

  } else {

      $headers = $headers."To: $to\r\nSubject: ".$subject."\r\n";

      if (! ($smtp = new Net_SMTP($host,$port))) {

          die("Unable to instantiate Net_SMTP object\r\n");

      }

      if (PEAR::isError($e = $smtp->connect())) {

          die($e->getMessage() . "\r\n");

      }

      if ($auth==1){

        if (PEAR::isError($ea = $smtp->auth($user, $pass ))) {

            die($ea->getMessage() . "\r\n");

        }

      }

      if (PEAR::isError($smtp->mailFrom($from))) {

          die("Unable to set sender to <$from>\r\n");

      }

      if (PEAR::isError($res = $smtp->rcptTo($to))) {

        die("Unable to add recipient <$to>: " . $res->getMessage() . "\r\n");

      }

      if (PEAR::isError($smtp->data($headers . "\r\n" . $body_mail))) {

          die("Unable to send data\r\n");

      }

      $smtp->disconnect();

  }

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.