PHP E-Mail Form Code
Moderator: General Moderators
PHP E-Mail Form Code
I am new to php so please forgive me. I am using dreamweaver cs4 and I am trying to create a form that will send the responses to my email. I have the following code. The code brings up up the confirmation page and everything, but I never get the email. Any help would be greatly appreciated.
<?php
/* Subject and E-Mail Variables */
$emailSubject = 'Date and Location Request';
$webMaster = 'username@gmail.com';
/* Gather Data Variables */
$studentsnameField = $_POST['studentsname'];
$parentsnameField = $_POST['parentsname'];
$locationField = $_POST['location'];
$highschoolField = $_POST['highschool'];
$hearField = $_POST['hear'];
$dayphoneField = $_POST['dayphone'];
$eveningphoneField = $_POST['eveningphone'];
$emailField = $_POST['email'];
$body = <<<EOD
<br><hr><br>
Students Name: $studentsname <br>
Parents Name: $parentsname <br>
City / State: $location <br>
Nearest High School: $highschool <br>
How did you hear about the Workshops?: $hear <br>
Daytime Phone: $dayphone <br>
Evening Phone: $eveningphone <br>
E-Mail: $email <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail(webMaster, $emailSubject, $body, $headers);
/* Results rendered as html */
$theResults = <<<EOD
<html>Deleted code to make easier to read</html>
EOD;
echo "$theResults";
?>
<?php
/* Subject and E-Mail Variables */
$emailSubject = 'Date and Location Request';
$webMaster = 'username@gmail.com';
/* Gather Data Variables */
$studentsnameField = $_POST['studentsname'];
$parentsnameField = $_POST['parentsname'];
$locationField = $_POST['location'];
$highschoolField = $_POST['highschool'];
$hearField = $_POST['hear'];
$dayphoneField = $_POST['dayphone'];
$eveningphoneField = $_POST['eveningphone'];
$emailField = $_POST['email'];
$body = <<<EOD
<br><hr><br>
Students Name: $studentsname <br>
Parents Name: $parentsname <br>
City / State: $location <br>
Nearest High School: $highschool <br>
How did you hear about the Workshops?: $hear <br>
Daytime Phone: $dayphone <br>
Evening Phone: $eveningphone <br>
E-Mail: $email <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail(webMaster, $emailSubject, $body, $headers);
/* Results rendered as html */
$theResults = <<<EOD
<html>Deleted code to make easier to read</html>
EOD;
echo "$theResults";
?>
Last edited by mdeppa on Wed Sep 28, 2011 1:51 pm, edited 1 time in total.
Re: PHP E-Mail Form Code
Code: Select all
$success = mail(webMaster, $emailSubject, $body, $headers);Re: PHP E-Mail Form Code
Celauran,
I noticed that after posting and have fixed it, but it sill does not work. I am at a loss. Would it be something with my host. I have network solutions and I am on a Unix server.
Thanks,
Michael
I noticed that after posting and have fixed it, but it sill does not work. I am at a loss. Would it be something with my host. I have network solutions and I am on a Unix server.
Thanks,
Michael
Re: PHP E-Mail Form Code
What is the mail function returning? Have you checked your sendmail logs?
Re: PHP E-Mail Form Code
Not sure. It may be getting above what I know. Here is the link to the website page: http://0349433.netsolhost.com/dates.html If you can quide where I need to check I will look at it. I really appreciate your help.
Michael
Michael
Re: PHP E-Mail Form Code
You're storing the return value of mail() in $success, so just var_dump($success)
Re: PHP E-Mail Form Code
Add the following
var_dump($success);
After the $success line? I tried that but with no success. Unless I am putting it in the wrong spot. I really appreciate it, I am sorry you have to walk we through all this like a child. I am a marketing person trying to do websites. It gets quite interesting.
var_dump($success);
After the $success line? I tried that but with no success. Unless I am putting it in the wrong spot. I really appreciate it, I am sorry you have to walk we through all this like a child. I am a marketing person trying to do websites. It gets quite interesting.
Re: PHP E-Mail Form Code
What do you mean you tried it with no success? It didn't output anything to screen?
Re: PHP E-Mail Form Code
Sorry about that. I was unable to get the email.
Re: PHP E-Mail Form Code
It wasn't meant to fix the email problem directly, it was meant to display whether or not the mail function worked. It should display either bool(TRUE) or bool(FALSE). We can work from there.
Re: PHP E-Mail Form Code
My lack of knowledge on this is showing up big time. I appreciate your patience. How or where does the var_dump need to be placed in the code to get it to display bool(TRUE) or bool(FALSE)
Re: PHP E-Mail Form Code
Right after
Code: Select all
$success = mail($webMaster, $emailSubject, $body, $headers);Re: PHP E-Mail Form Code
I placed the code as follow:
$success = mail($webMaster, $emailSubject, $body, $headers);
var_dump($success);
Once I submit the form it brings up my html response.
$success = mail($webMaster, $emailSubject, $body, $headers);
var_dump($success);
Once I submit the form it brings up my html response.
Re: PHP E-Mail Form Code
I still have the rest of the code, just added the var_dump($success);