Jump to content

Problem sending email with php form


hatefulcrawdad

Recommended Posts

You wrote it so if $emailMessage is blank, it won't send. $emailMessage will always be "\n----MESSAGE-----\n" even if they entered a message or not. You'd just need to check the POST not the variable. Try this:

<?php
if (isset($_POST['Name'])){
$emailTo = 'cm@chrismdesign.com';
$emailName = $_POST['Name'];
$emailFrom = $_POST['Email'];
$emailSubject = $_POST['Subject'];
$emailMessage = "\n-----MESSAGE-----\n" . $_POST['Message'];
$emailMessage .= "\n-----NAME-----\n" . $_POST['Name'];
$emailMessage .= "\n-----EMAIL-----\n" . $_POST['Email'];


if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'Please enter a valid email address';
} elseif (empty($emailName)) {
echo 'Please enter your name';
} elseif (empty($emailSubject)) {
echo 'Please enter a subject';
} elseif (empty($_POST['Message'])) {
echo 'Please enter a message';
} else {
if (!empty($emailFrom)) {
$emailHeaders = 'FROM: <cm@chrismdesign.com>';
}
    
/* Send Email */
if (mail($emailTo, $emailSubject, $emailMessage, $emailHeaders)) {
echo 'You message has been sent!';
} else {
echo 'There was an internal error whilst sending your email.<br>';
echo 'Please try again later.';    
}
}
}
?>

 

A simple mistake to make.

Link to comment
Share on other sites

You wrote it so if $emailMessage is blank, it won't send. $emailMessage will always be "\n----MESSAGE-----\n" even if they entered a message or not. You'd just need to check the POST not the variable. Try this

 

...code deleted for length...

 

A simple mistake to make.

 

OMG, thank you so much. What is with that guy trying to get headers defined when it already is? wierd. But anyway, you are a complete life saver. I am set with this contact form, not just gotta style the bitch.

Link to comment
Share on other sites

No problem! I spoke from experience when I first made a contact form..

 

Since your problem is solved, hit the 'Topic Solved' button on the bottom left of this thread.. We try to get as many users as we can to use it .

 

EDIT: That guy doesn't know much about programming, Not sure why he babbles on like that. He's pretty good with some things though..

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.