Hi all,
I have been trying to create an email form that allows me to send an email to a hotmail, gmail address but everytime i do this it fails and i dont recieve the email. I am relativly new to PHP and dont really have much experience and was wondering if one of you good people could possibly create a simple form or point me in the direction of a good tutorial.
I would be extreamly greatful if someone could help me out with this as i am really struggling with this and need it to complete my website.
Thanks for your time and any help
Mike
Email Form Help
Moderator: General Moderators
Re: Email Form Help
the code i currently have is below. Please could someone help me out with this.
Thanks
Mike
Code: Select all
<html>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("mike2fast135@hotmail.com", "$subject",
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html> Mike
Re: Email Form Help
start by taking the quotes off of your $subject variable, any reason you are using $_REQUEST instead of $_POST since you are posting data to the page? And I believe with hotmail and gmail, and it's good practice anyway, to use headers i.e.
I would do this...
Code: Select all
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
then use mail($to, $subject, $message, $headers);
Code: Select all
<html>
<body>
<?php
if (isset($_POST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "mike2fast135@hotmail.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' .$email. '<'.$email.'>' . "\r\n";
$headers .= 'Reply-To: ' .$email. ' "\r\n";
$headers .= 'Return-Path: '.$email.' "\r\n";
mail($to, $subject, $message, $headers);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html> Re: Email Form Help
Hi,
Thanks for your reply i really appreciate it. Unfortunatly when i upload this i get 500 internal server error
Any ideas why?
Thanks for your reply i really appreciate it. Unfortunatly when i upload this i get 500 internal server error
Any ideas why?