Jump to content

Problems With Php Mail Function.


phingoc

Recommended Posts

Hi. When i fill out my form and press "send", i get a email, so that is working.. But the email only contains "name" and "subject".. The senders email adress and message is missing from the mail i reciev.

 

Form

<form name="contact" method="POST" action="send_contact.php">
<br><br>
<img src="img/name.png"><br>
<input type="text" name="name" id="name" size="25"><br><br>
<img src="img/email.png"><br>
<input type="text" name="email" id="email" size="25"><br><br>
<img src="img/subject.png"><br>
<input type="text" name="subject" id="subject" size="25"><br><br>

</td>
<td width="55%" valign="top">

<br><br>
<img src="img/message.png"><br>
<textarea rows="8" cols="35" type="text" name="message" id="message"></textarea><br><br>
<div align="right"><input type="image" src="img/submit.png" value="submit"></div>
</form>

 

And "send_contact.php"

 

<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "[email protected]";
mail("$to","$subject","$message","from:$name<$email>") or die("Something went wrong, please go back and try again.");

echo "Thank you for contacting me.";
?>

 

What to do?

Link to comment
https://forums.phpfreaks.com/topic/268755-problems-with-php-mail-function/
Share on other sites

Added reply-to & FROM headers if you still are wanting to use Mail over a more advanced class like PHPMailer.

<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "[email protected]";
headers = "From: \"".$name."\" <".$email.">\n"; 
$headers .= "Return-Path: <".$email.">\n"; 
mail($to,$subject,$message,$headers) or die("Something went wrong, please go back and try again.");

echo "Thank you for contacting me.";
?>

adding isset() to make sure values are set.

 

<?php
$name= isset($_POST['name']) ? $_POST['name'] : '';
$subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$to = "[email protected]";
headers = "From: \"".$name."\" <".$email.">\n";
$headers .= "Return-Path: <".$email.">\n";
mail($to,$subject,$message,$headers) or die("Something went wrong, please go back and try again.");

echo "Thank you for contacting me.";
?>

 

if there is nothing in the value that value will just send blank. if it is not sending at all as mentioned output each variable with print_r and tell us what the output is.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.