Forum Moderators: coopster
Parse error: syntax error, unexpected T_VARIABLE in /homepages/37/d404090856/htdocs/c5/send_form_email.php on line 30
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['suject'];
$details = $_POST['details'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'contact@example.com';//<== update the email address
$email_subject = "$subject";
$email_body = "$details"
$to = "formsubmissions@example.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: http://example.com/thanks-for-contacting');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<form id="payment" method="post" action="send_form_email.php">
<fieldset>
<ol>
<li>
<label for=name>Name</label>
<input id=name name=name type=text placeholder="First and last name" required autofocus>
</li>
<li>
<label for=email>Email</label>
<input id=email name=email type=email placeholder="example@domain.com" required>
</li>
<li>
<label for=phone>Phone</label>
<input id=phone name=phone type=tel placeholder="(000) 000-0000" required>
</li>
<li>
<label for=subject>Subject</label>
<input id=subject name=subject type=text required>
</li>
<li>
<label for=details>Details</label>
<textarea id=details name=details rows=5 required></textarea>
</li>
</ol>
</fieldset>
<fieldset>
<button type="submit" value="submit">Submit!</button>
</fieldset>
</form>
[edited by: eelixduppy at 9:36 pm (utc) on Feb 29, 2012]
[edit reason] exemplified domain [/edit]
$email_body = "$details"
error; you need to submit the form!
Warning: Cannot modify header information - headers already sent by (output started at /homepages/37/d404090856/htdocs/c5/send_form_email.php:5) in /homepages/37/d404090856/htdocs/c5/send_form_email.php on line 36 if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
<html>
<head></head>
<body>
<form id="payment" method="post" action="mail.php">
<fieldset>
<ol>
<li>
<label for=name>Name</label>
<input id=name name=name type=text placeholder="First and last name" required autofocus>
</li>
<li>
<label for=email>Email</label>
<input id=email name=email type=email placeholder="example@domain.com" required>
</li>
<li>
<label for=phone>Phone</label>
<input id=phone name=phone type=tel placeholder="(000) 000-0000" required>
</li>
<li>
<label for=subject>Subject</label>
<input id=subject name=subject type=text required>
</li>
<li>
<label for=details>Details</label>
<textarea id=details name=details rows=5 required></textarea>
</li>
</ol>
</fieldset>
<fieldset>
<button type="submit" value="submit">Submit!</button> <button type="reset" value="reset">Reset</button>
</fieldset>
</form>
</body>
</html>
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$details = $_POST['details'];
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_subject = "$subject";
$email_body = "$details";
$to = "you@yourdomain.fu"; //CHANGE
$headers = "From: $name";
$headers = "Reply-To: $visitor_email";
mail($to, $email_subject, $email_body, "From: $name <$email>\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n$headers");
header('Location: thanks.php');
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>