E-A-S-Y question php syntax with mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

E-A-S-Y question php syntax with mail

Post by forzato »

Newbie's PHP server script question:

Assuming the balance of this PHP server script code (not shown) is correct why won't this mail to the address provided in the variable 'email' ???

$sendTo = $_POST["email"];
mail($sendTo, $subject, $message, $headers);


Thanks in advance.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Please post more code.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Sounds as if you are not sending the proper headers.
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Addendum to above question...

Post by forzato »

Code: Select all

<?php
$sendTo = $_POST["email"];
$subject = "*** Instant Email Response  ***";
$headers = "From: " . $_POST["email"] ." "."<" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$message = $_POST["email"] ; 
mail($sendTo, $subject, $message, $headers);
?>
Is complete code to above question... thanks for the help!

PHENOM | PLEASE READ POSTING GUIDLINES
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

This code worked until I changed this...

$sendTo = "myemailaddress@snet.netl";

to this...

$sendTo = $_POST["email"];

...in an effort to send the email to the address stated in the variable 'email' that gets sent to this server script.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Try echo'ing out the variable and make sure it is what you are expecting, perhaps.
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

Phenom,

You'll have to excuse my ignorance... but when I say Newbie I meam it!

Do some splainin' Lucy! ...'echo'???
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Run this code before your mail function. It will show you what is in your $_POST array:

Code: Select all

<?php
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

echo $_POST['email']; 
//or
print_r($_POST); //to see all your form values

put that at the top of your script.. is it what you are expecting?

nice 1 hawleyjr
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

Just to reiterate...

The code works tried and tested - EXCEPT - when I change that one line from a simple "myemailaddress@snet.net" to this whole $_POST["email"] thing...

...the variable 'email' IS a valid email address and is transmiting to the script (as proven when I substitute a plain old email address in quotes for the $_POST["email"] thing...

Thanks
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

I'll try the echo idea right now
Thanks... I'll let you know either way!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

can you show us the result from your print_r($_POST);

and also I notice you use $_POST['email'] for multiple purposes...including the email address and message itself, mistake?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

To Phenom's point about being the same to and from email address. some servers won't let email in that has the same domain name as the server domain name.
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

Tried the ol' print_r($_POST); technique... nothing.

Let me give a quick background...
Web site is Flash swf file that sends variable 'email' to the server script provided in this post.
The swf and php files DO WORK, and reliably do their job ONLY if the $sendTo is defined as a simple email like...

myemailaddress@snet.net

Now I'd like to modify the php script to send an email not to myemailaddress@snet.net, but rather to an email address sent to the php script from the flash swf in the form of variable "email"

Maybe this isn't as simple as swapping the static email address for a variable sent to the php server side script ???

Thanks for any input.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

There are pre-built flash->PHP mail scripts out there. Google Flash and PHP
Post Reply