Mail sending failed

the mail() function

Moderators: macek, egami, gesf

sunnydesuja
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Apr 03, 2012 9:13 pm

Mail sending failed

Postby sunnydesuja » Tue Apr 03, 2012 9:30 pm

Hi Guys,

I am new to php and i am using this code to send mail but it is giving error mail sending failed...

Please help me on this

Code: Select all

<?php

   //$name=$_POST['name'];   
   $contact=$_POST['contact'];
   $time=$_POST['time'];
   $state=$_POST['state'];
   $zipcode=$_POST['zipcode'];
   //$emailaddress=$_POST['emailaddress'];
   $medication=$_POST['medication'];
   $dosage=$_POST['dosage'];
   $radiobutton1=$_POST['radiobutton1'];
   $radiobutton2=$_POST['radiobutton2'];
   $radiobutton3=$_POST['radiobutton3'];

$emailsubscribe=$_POST['emailaddress'];
$_SESSION['Email']=$emailsubscribe;
$name=$_POST['name'];

$mail_body="Details \n";
$mail_body .="Name : ";
$mail_body .="$name \n";

$mail_body .="Contact Number: ";
$mail_body .="$contact \n";

$mail_body .="Best Time to reach : ";
$mail_body .="$time \n";

$mail_body .="State : ";
$mail_body .="$state \n";

$mail_body .="ZipCode : ";
$mail_body .="$zipcode \n";

$mail_body .="Email Address : ";
$mail_body .="$emailsubscribe \n";

$mail_body .="Medications that you take regularly: ";
$mail_body .="$medication \n";

$mail_body .="Name and Dosage of the Medications: ";
$mail_body .="$dosage \n";

$mail_body .="Do you take medication for Sexual Health: ";
$mail_body .="$radiobutton1 \n";

$mail_body .="What medication do you prefer for sexual health: ";
$mail_body .="$radiobutton2 \n";

$mail_body .="Where do you purchase your medication from: ";
$mail_body .="$radiobutton3 \n";

$headers="Mail From :". " ".  $emailsubscribe;

if(mail("ajay.saar@gmail.com",'RX-CarePharma Inquiry form filled',$mail_body,$headers))
{
            
   echo "<script>window.location.href='rx-thanks.html';</script>";
}
else
{      
   echo "<script>alert(\"Mail sending failed\"); window.location.href='RX-care.html'; </script>";
}
      
?>

LadyKYra
New php-forum User
New php-forum User
Posts: 9
Joined: Tue Feb 07, 2012 9:36 pm

Re: Mail sending failed

Postby LadyKYra » Fri Apr 06, 2012 3:16 am

Hello sunny, I dont hve much time to read ur codes. You can check this out, it is an example from w3school
Idk if this will clear out things, but it can help. xD
<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</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: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
?>


Return to “PHP coding => Mail”

Who is online

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