Web Hosting Talk







View Full Version : PHP Mail (Sender: Nobody)


cmimrie
04-09-2007, 07:19 PM
Hello.

So I have a script which is emailing users a URL.

Here are the two parts of the code;

config.inc.php
//mail setup
$msubject = "Example Subject";
$mbody= "Uploaded: [url]";
$mheaders = "";

upload.php

if ( $_POST[email] ) {
mail($_POST[email],$msubject,str_replace("[url]",urln($filex,$rn,$baseurl),$mbody));
}


Now I have set the following in the httpd.conf;

php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f example@example.com"

Now everything is partially fine and dandy, as before I implemented the http line, it would send you an email from nobody@yourserverhostname.com and since the above modification it emails from example@example.com. However, the sender still shows as Nobody does anybody know how to modify this setting to show Example or my choice of Sender, I have tried many times and have yet to find a working solution.

Any help is much appreciated.

horizon
04-09-2007, 07:35 PM
Replace:


if ( $_POST[email] ) {
mail($_POST[email],$msubject,str_replace("[url]",urln($filex,$rn,$baseurl),$mbody));
}

with:


if (isset($_POST['email']) && preg_match("/^\w(\.?[\w-])+@\w(\.?[\w-])+\.[a-z]{2,4}(\.[a-z]{2})?$/i", $_POST['email'])) {
mail($_POST['email'], $msubject, str_replace('[url]', urln($filex,$rn,$baseurl), $mbody));
}

cmimrie
04-09-2007, 07:40 PM
That has no relation to the Nobody issue however.

Although I have implemented your modification, thanks.

horizon
04-09-2007, 08:00 PM
Right. The $mbody tag. Without knowing from which user information you're using to capture your recipient's name, let's try to:

replace:


$mbody= "Uploaded: [url]";


with:


$mbody= "Uploaded: {url}";


Then,


if ( $_POST[email] ) {
mail($_POST[email],$msubject,str_replace("[url]",urln($filex,$rn,$baseurl),$mbody));
}


with:


if (isset($_POST['email']) && preg_match("/^\w(\.?[\w-])+@\w(\.?[\w-])+\.[a-z]{2,4}(\.[a-z]{2})?$/i", $_POST['email'])) {
mail($_POST['email'], $msubject, preg_replace('/^{url}/i', urln($filex,$rn,$baseurl), $mbody));
}

cmimrie
04-09-2007, 08:08 PM
I don't quite think you understand what issue I am facing.

**Attached Image**

This shows what I mean about the incoming emails showing 'Nobody' as the sender.

horizon
04-09-2007, 09:39 PM
I think you would need to instantiate a class file in order to use an object that could declare a firstname, lastname, email address ect . . .

Engelmacher
04-10-2007, 04:42 AM
Include a reply-to header.

Ks Jeppe
04-10-2007, 05:07 PM
Man you keep confusing and misleading people on these php threads horizon :s rather sad to see...

sixtyclear: A small trip to the php manual for mail() might solve your question :) You need to include the "From" header like so:
<?php
$mheaders = "From: Example <example@example.com> \r\n";

if (isset($_POST['email']) && preg_match("/^\w(\.?[\w-])+@\w(\.?[\w-])+\.[a-z]{2,4}(\.[a-z]{2})?$/i", $_POST['email'])) {
mail($_POST['email'], $msubject, str_replace('[url]', urln($filex,$rn,$baseurl), $mbody), $mheaders);
}
?>

cmimrie
04-10-2007, 05:27 PM
Thanks Ks Jeppe

Worked a treat.

Ks Jeppe
04-10-2007, 05:33 PM
Thanks Ks Jeppe

Worked a treat.
You're welcome :) If you need any more php help, my pm inbox is always open :)

Engelmacher
04-10-2007, 06:42 PM
Man you keep confusing and misleading people on these php threads horizon :s rather sad to see...

I wouldn't call it "misleading" so much as "posting random garbage that has nothing to do with anything."

Ks Jeppe
04-11-2007, 08:18 AM
I wouldn't call it "misleading" so much as "posting random garbage that has nothing to do with anything."
Ay, i stand corrected :P