PHP E-Mail Form Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

PHP E-Mail Form Code

Post by mdeppa »

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";

?>
Last edited by mdeppa on Wed Sep 28, 2011 1:51 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

Code: Select all

$success = mail(webMaster, $emailSubject, $body, $headers);
Missing the $ in $webMaster.
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

What is the mail function returning? Have you checked your sendmail logs?
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

You're storing the return value of mail() in $success, so just var_dump($success)
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

What do you mean you tried it with no success? It didn't output anything to screen?
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

Sorry about that. I was unable to get the email.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

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.
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

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)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

Right after

Code: Select all

$success = mail($webMaster, $emailSubject, $body, $headers);
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP E-Mail Form Code

Post by Celauran »

Nothing above that?
mdeppa
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:38 pm

Re: PHP E-Mail Form Code

Post by mdeppa »

I still have the rest of the code, just added the var_dump($success);
Post Reply