...

View Full Version : $headers .= 'From: '.$name.'<'.$from.'>'."\n";



Nealec
01-10-2012, 07:59 PM
Trying to send email to all users in db all works fine but it wont use my name or email. when i check inbox they are all from ****@cpanel42.uk2.net, i need it to look like,

From: My Name - my@email.co.uk


<?php

$dbhost = '';
$dbuser = '';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

mysql_select_db("", $conn);

$name = "My Name";
$from = "my@email.co.uk";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= 'From: '.$name.'<'.$from.'>'."\n";
$subject = "Subject";
$body = $message;

$query = mysql_query("SELECT email FROM users") or die(mysql_error());

while(list($email) = mysql_fetch_row($query)) {
mail($email, $subject, $body, $headers);
}

?>

I can get it to use just my email if i add "-f my@email.co.uk" but i really want to add my name

Fou-Lu
01-10-2012, 09:20 PM
\r\n isn't correct in either from or content-type. Correct those first and try again.
i seem to recall seeing a similar issue to this in the past, but I can't recall what the cause or solution was. I think that one was pegged directly on the host.

Nealec
01-10-2012, 09:45 PM
\r\n isn't correct in either from or content-type. Correct those first and try again.
i seem to recall seeing a similar issue to this in the past, but I can't recall what the cause or solution was. I think that one was pegged directly on the host.

Worked great after fixing them, thankyou very much. Though there is one small thing, it says the email is From: My Name - my@email.co.uk which is perfect but straight after that it says via cpanel42.uk2.net. is there any way to get rid of that? Its no big deal if there isnt i just thought it would look tidier without it.

Fou-Lu
01-10-2012, 10:00 PM
If you delimited the from with the \r\n and it still appends that, then no aside from adding an alternate configuration to the mailer in the additional parameters or writing your own smtp. Check with your host as well, some of them like using custom forms instead of direct mailers (which IMO is a company I would never deal with).

Nealec
01-10-2012, 10:06 PM
Ok ill try that or i can deal with it for now, thanks for all the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum