Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialArturo Gutierrez
11,414 PointsIs there something wrong with my PHP Code? Can't receive any emails when submitting.
I set the method equal to post and set the action to a separate file page. The code below is what the action command is attached to.
$case_number = $_POST['caseNumber'];
$judgement_amount = $_POST['judgmentAmount'];
$amount_collected = $_POST['amountCollected'];
$date_issued = $_POST['dateIssued'];
$state_issued = $_POST['stateIssued'];
$attorney = $_POST['attorney'];
$default_award = $_POST['defaultAward'];
$debtor_state = $_POST['debtorState'];
$debtor_name = $_POST['debtorName'];
$debtor_address = $_POST['debtorAddress'];
$debtor_location = $_POST['debtorLocation'];
$full_name = $_POST['fullName'];
$street_address = $_POST['streetAddress'];
$location = $_POST['location'];
$phone_number = $_POST['telephone'];
$email = $_POST['email'];
$description = $_POST['description'];
$to = "sample@yahoo.com";
$subject = "New Client!";
mail($to,$subject,"From: " . $full_name);
echo "Your message has been sent";
?>```
2 Answers
Joel Bardsley
31,249 Pointsmail($to,$subject,"From: " . $full_name);
Is "From: " . $full_name your message or are you setting the "From:" header?
If it's your message, then you may need to add a "From:" header as a fourth parameter in your mail function. While the additional headers parameter is optional, the mail must contain a "From:" header. You can either add it via the additional parameter in mail() or set a default one in your php.ini file.
If it's your "From:" header, there are two problems: 1. Your message parameter is missing; 2. The "From:" header format is invalid as you are just providing the full name rather than the email address. Examples of a valid "From:" header are:
From: user@domain.com
From: "user" <user@domain.com>
Hope that helps.
Adam Duffield
30,494 PointsI'm no mail expert but have you tried your spam folder? Php mail function isn't widely trusted so ends up in spam a lot.
Regards,
Adam