Page 1 of 3
E-A-S-Y question php syntax with mail
Posted: Sat Mar 19, 2005 5:58 pm
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.
Posted: Sat Mar 19, 2005 6:00 pm
by hawleyjr
Please post more code.
Posted: Sat Mar 19, 2005 6:01 pm
by John Cartwright
Sounds as if you are not sending the proper headers.
Addendum to above question...
Posted: Sat Mar 19, 2005 6:03 pm
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
Posted: Sat Mar 19, 2005 6:06 pm
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.
Posted: Sat Mar 19, 2005 6:08 pm
by John Cartwright
Try echo'ing out the variable and make sure it is what you are expecting, perhaps.
Posted: Sat Mar 19, 2005 6:10 pm
by forzato
Phenom,
You'll have to excuse my ignorance... but when I say Newbie I meam it!
Do some splainin' Lucy! ...'echo'???
Posted: Sat Mar 19, 2005 6:13 pm
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>';
?>
Posted: Sat Mar 19, 2005 6:13 pm
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
Posted: Sat Mar 19, 2005 6:14 pm
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
Posted: Sat Mar 19, 2005 6:15 pm
by forzato
I'll try the echo idea right now
Thanks... I'll let you know either way!
Posted: Sat Mar 19, 2005 6:16 pm
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?
Posted: Sat Mar 19, 2005 6:17 pm
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.
Posted: Sat Mar 19, 2005 6:27 pm
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.
Posted: Sat Mar 19, 2005 6:29 pm
by hawleyjr
There are pre-built flash->PHP mail scripts out there. Google Flash and PHP