Question:
What is wrong with this PHP script?
R. Arnold
2007-10-03 12:35:31 UTC
I have a contact form in flash. I can't seem to get it to work (send to my e-mail.) Here is the actionscript;

on (release) {
_parent.getURL("contact.php", "_blank","GET");

_parent.name="your name:";
_parent.email="e-mail:";
_parent.phone="phone:";
_parent.message="message:";
}
//And here is my PHP script (titles contact.php);
$name=$_GET["name"];
$email=$_GET["email"];
$phone=$_GET["phone"];
$message=$_GET["message"];

$recipient_email="ryan081232@yahoo.com";

$subject="from", $email;
$headers.="From", $name;, "<".$email."> \n";
$headers.="Content type: text/html; charset=windows-1252\n";

$content = "Contact Form";
$content = "name:".$name."
";
$content = "email:".$email."
";
$content = "phone:".$phone."
";
$content = .$message.;
$content = "";
mail($recipient_email, $subject, $content, $headers);
?
Four answers:
anonymous
2007-10-03 13:33:14 UTC
First, you delimit associative variable names with single-quotes, not double-quotes, e.g., $_GET['name'], not $_GET["name"]



Second, you concatenate strings with periods, not commas, and it's not necessary to concatenate a string if you delimit it with double quotes, e.g., $subject = "from $email";



Third, as previously noted, not all PHP servers support the mail command, as it is susceptible to injection attacks.



Fourth, you concatenate properly some text to $headers when it contains nothing, and you fail to concatenate your content string.




$name = $_GET['name'];

$email = $_GET['email'];

$phone = $_GET['phone'];

$message = $_GET['message'];



$recipient_email = "ryan081232@yahoo.com";



$subject = "from $email";

$headers = "From $name <$email>\n";

$headers .= "Content type: text/html; charset=windows-1252\n";



$content = "Contact Form";

$content .= "name: $name< br />";

$content .= "email: $email< br />";

$content .= "phone: $phone< br />";

$content .= $message;

$content .= "";

mail($recipient_email, $subject, $content, $headers);

?>



You need to remove the spaces in < br />; Answers won't show the tag otherwise.
anonymous
2007-10-03 13:02:32 UTC
Many servers do not allow auto generated emails, check your hosting company. Also check the mail() function in the php manual, as you are sending this does not actually set a sender address, there is a fifth parameter which can be used :



mail($recipient_email,$subject,$content,$headers,'-f$email')

This correctly sets a sender address rather than a <>(empty). Empty senders tend to get blocked by the server. Setting the fifth parameter also ensures correct returns in case of an error. You should set your script to enter the sender name in the content, not in the header, also you do not need the <> around the from address. A good idea is to post this information to a database, as you can use this to automate it's use and it covers against the loss of an email for any reason.
Quirkey
2007-10-03 12:38:21 UTC
Try this:




$name=$_GET["name"];

$email=$_GET["email"];

$phone=$_GET["phone"];

$message=$_GET["message"];



$recipient_email="ryan081232@yahoo.com";



$subject="from ".$email;

$headers = "From:".$name;."<".$email.">\n";

$headers .="Content type: text/html; charset=windows-1252\n";



$content = "Contact Form";

$content .= "name:".$name."
";

$content .= "email:".$email."
";

$content .= "phone:".$phone."
";

$content .= .$message.;

$content .= "";

mail($recipient_email, $subject, $content, $headers);

?>
thubanconsulting
2007-10-03 12:57:20 UTC
You have typos in multiple places. Watch your comma and period placement.



Before:

$subject="from", $email;

$headers.="From", $name;, "<".$email."> \n";

$headers.="Content type: text/html; charset=windows-1252\n";



After:

$subject="from". $email;

$headers ="From". $name;, "<".$email."> \n";

$headers ="Content type: text/html; charset=windows-1252\n";


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...