Forum Moderators: coopster

Message Too Old, No Replies

php mail

one script works , one works but... the third does not...why?

         

cyberbites

1:34 am on Feb 22, 2006 (gmt 0)

10+ Year Member



This one works perfectly

<?php
$to = "me@mydomain.com";
$subject = $_POST['subject'];
$body = $_POST['body'];
$headers="From: " . $_POST['emailAddress'] ."\n";
mail($to,$subject,$body,$headers);
?>
hooray.

This one (same domain, different directory at the same level) sends mail but the return/From has _______@web.pas.earthlink.net appended to it -- why is that?

<?php
$to = "mikep@example.com";
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
$headers="From: " . $_POST['emailAddress'] ."\n";
mail($to,$subject,$body,$headers);
?>
-- and --
This one doesn't work... I can't see it, can you? please?

<?php
$to = "me@mydomain.com";
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$streetAddress = $_POST['streetAddress'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$helpCities = $_POST['helpCities'];
$comments = $_POST['comments'];
$headers="From: " . $_POST['emailAddress'] ."\n";
mail($to,$firstName,$lastName,$email,$streetAddress,$city,$state,$zip,$helpCities,$comments,$headers);
?>

Thanks for your help.
Mike

[edited by: jatar_k at 3:01 am (utc) on Feb. 22, 2006]
[edit reason] generalized email [/edit]

jatar_k

3:04 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld cyberbites,

I am not sure why the second appends to the from, I can only guess something is different with the data being sent as there is little or no difference in the code

the third one I can tell you

bad mail function call
mail($to,$firstName,$lastName,$email,$streetAddress,$city,$state,$zip,$helpCities,$comments,$headers);

the aboce is not valid, way too many parameters. My wild guess is you want to add alll of those to the body of the email. You need to concatenate them all into a single var and then pass that as the body of the email.

cyberbites

5:44 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



Thanks!
...so, may I concatenate those parameters to be sent as body by

<?php
$to = "me@mydomain.com";
$subject = $_POST['subject'];
$body = $_POST['$to . $firstName . $lastName . $email, . $streetAddress . $city . $state . $zip . $helpCities . $comments'];
$headers="From: " . $_POST['emailAddress'] ."\n";
mail($to,$subject,$body,$headers);
?>

Or have I the wrong form again...?
Thanks
Mike

jatar_k

8:23 pm on Feb 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that looks right at a glance

did it work?

cyberbites

5:17 am on Feb 26, 2006 (gmt 0)

10+ Year Member



<did it work...?>

No, it didn't...

I'm not clear why, but then I'm new to php...Ah,well.

cyberbites

5:33 am on Feb 26, 2006 (gmt 0)

10+ Year Member



I should mention that
...it did send mail, but the subject and all the rest of the content were missing and the sender was, once again
www.mydomain@web.pas.earthlink.net

jatar_k

6:12 am on Feb 26, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well there are a bunch of mail headers you can use. I have used this set to great success for ages

$headers = '';
$sourceemail = $_POST['emailAddress'];
$myname = 'Mr Bo Jangles';
$headers .= "From: " . $myname . " <" . $sourceemail . ">\r\n";
$headers .= 'Subject: ' . $subject . "\r\n";
$headers .= "Return-Path: " . $sourceemail . "\r\n";
$headers .= "Reply-To: " . $sourceemail . "\r\n";
$headers .= "Content-type: text;\r\n";
$headers .= "Mime-Version: 1.0\r\n";

I apologize, I obviously didn't look at your above post or I was dead when I did

this line is wrong
$body = $_POST['$to . $firstName . $lastName . $email, . $streetAddress . $city . $state . $zip . $helpCities . $comments'];

should be something like this

$body = $_POST['to'] . "\n" . $_POST['firstName'] . "\n" . $_POST['lastName'] . "\n" . $_POST['email'] . "\n" . $_POST['streetAddress'] . "\n" . $_POST['city'] . "\n" . $_POST['state'] . "\n" . $_POST['zip'] . "\n" . $_POST['helpCities'] . "\n" . $_POST['comments'] . "\n";

I seperated each value with a new line. man am I sorry, I can't believe I did that.

Try that with line with those headers and try again