html - error occurs when sending form data to mail using php -
i'm trying send or write code sending email form, each time submit, "error occurred" statement had specified in if else statement, hence mail can't sent. problem? here code.
<!doctype html> <html> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>email us</title> <body> <form action="email_us.php" name="quotation" method="post"> <input type="text" name="fname" placeholder="first name"><br> <input type="text" name="email" placeholder="enter email"><br> <input type="text" name="subject" placeholder="subject"><br> <input type="text" name="message" placeholder="message"><br><br> <input type="submit" name="submit" value="request quotation"> </form> </body> </html> <?php if(isset($_post["submit"])){ $fname=$_post["fname"]; $email=$_post["email"]; $subject=$_post["subject"]; $message=$_post["message"]; $to = "mymail@email.com";//i changed posting purposes. $from = $email; $headers .= "from: ".$from."\r\n". "reply-to: ".$from."\r\n". "x-mailer: php/".phpversion(); $headers .= "content-type:text/html;charset=utf-8" . "\r\n"; $headers .= "mime-version: 1.0 \r\n"; if(mail($to, $subject, $message, $headers)){ echo "mail sent"; }else{ echo "error occurred"; } } ?>
are assume code stored in file email_us.php?
maybe change line #25 from:
$headers .= "from: ".$from."\r\n".
to:
$headers = "from: ".$from."\r\n".
as first time define $headers variable, don't need concat string.
Comments
Post a Comment