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 = "xxx@xxx.xx";
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?

Edited by phingoc
Link to comment
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 = "xxx@xxx.xx";
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.";
?>

Link to comment
Share on other sites

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 = "xxx@xxx.xx";
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.

Edited by darkfreaks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.