Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Send Form to Email address problems

the mail() function

Moderators: macek, egami, gesf

Send Form to Email address problems

Postby ettedo2000 » Sun Jun 02, 2013 7:14 am

Hello everyone,
I need some help with a php script. I have a small website and I want to have a Registration Form that is send to my Email address. My Form is going to be a simple HTML page asking the user for name, Email and comment.
The form action will send it to my PHP form. Once error check is completed, it will be send the form to my Email address. I have read many post looked at a lot of codes and I still can’t get it to work. Once I fill out the form and submit it, the php shows that it has successfully send but I never get an Email.
Do I need to do something special on my server side to get the Form to work properly? I checked with my server host to see if php is accepted and working. They said yes but could not help me in figuring out why it is not working. I hope someone here can help me.
I included my php code here:

Code: Select all
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];


if(!isset($_POST['submit']))
{
   
   echo "error; you need to submit the form!";
}

if(empty($name)||empty($email))
{
    echo "Name and email are mandatory!";
    exit;
}
if(!empty($Email))
      {
   if (!filter_var($Email, FILTER_VALIDATE_EMAIL))         //If Email is not correct return error message
   {
      echo "<p>You entred an incorect Email (jon@email.com)!</p>\n";
      exit();
   }
}
   

$email_from = 'myemail@live.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
    "Here is the message:\n $message".
   
$to = "myemail@live.com";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $email \r\n";

//Send the email!
mail($to,$email_subject,$email_body,$headers);

//done. redirect to thank-you page.
header('Location: thank-you.html');
 
?>

ettedo2000
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Jun 02, 2013 3:52 am

Re: Send Form to Email address problems

Postby developerahusain » Sun Jun 02, 2013 8:52 am

Here is the code friend. Actually 1 year back i developed this code through taking a tutorial about php mail php official website. This code will definitely work for you. And there is html form below this. You can modify and use it. Any problem do revert

$to =$_POST['to'];
$subject ='Job Opportunity @ m`brace';
$message ='<head>
<title>Untitled Document</title>
</head>

<body>
<table width="650" cellpadding="0" cellspacing="0" style="font-family:arial">
<tr><td><img src=logo.png width=150></td></tr>
</table>
</body>
</html>
';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From:'.$_POST['from']."\r\n";

mail($to,$subject,$message,$headers);
echo "<script language='javascript'>window.location='?do=msg1'</script>";

<form name="mail" method="post">
<table width="500" cellpadding="0" cellspacing="0" class="style12a" align="center">
<tr>
<td bgcolor="2459C2" colspan="2" class="style14f" align="center" ><strong>Send Mail</strong>
<input type="hidden" value="mbrace.cloud@gmail.com" name="from"></td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td width="200"><p class="subtextl">Name</p></td>
<td width="300"><p class="subtext_right">
<input type="text" name="name" value="" size="40">
</p></td>
</tr>
<tr>
<td width="200"><p class="subtextl">Email</p></td>
<td width="300"><p class="subtext_right">
<input type="text" name="to" value="" size="40">
</p></td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr valign="top" bgcolor="8FD8F9">
<td>&nbsp;</td>
<td><p class="subtext_right"><input type="submit" value="Send" name="submit" class="style_form">
</p></td>
</tr>
</table>
</form>
</body>
</html>

Regards
developerahusain
developerahusain
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow


Return to PHP coding => Mail

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron