?
Solved

Why doesn't this email script work?

Posted on 2011-03-09
4
Medium Priority
?
251 Views
Last Modified: 2012-05-11
Here's my code:

$email_address = trim($_POST['email']);
$name = trim($_POST['name']);
$phone = trim($_POST['phone']);
$time_frame = trim($_POST['time_frame']);
$underground = "christopher@undergroundtreehouse.com";

$to  = $email . ', '; // note the comma
$to .= 'christopher@undergroundtreehouse.com';
$subject = "The Underground Treehouse Demo Service";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <christopher@undergroundtreehouse.com>' . "\r\n";
$subject = "The Underground Treehouse";
$message .= "<b>Thank you for contacting the \"Underground Treehouse!\"</b><P>You will be contacted shortly.<P>Thanks again!";
mail($to, $subject , $message, $headers);

I don't know how to test it without sending multiple emails (which I have been doing), but I'm hoping some ninja can look at this and identify a problem that I currently can't see.

Thoughts?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 664 total points
ID: 35088666
You don't actually say what is wrong with the mail. "Doesn't work" is not very helpful in diagnosis.

Having said that....

1) You have "$subject = " on two lines, so one wipes the other

2) $headers .= 'From: <christopher@undergroundtreehouse.com>' . "\r\n"; should not have < and > in there

3) None of your data is cleaned to prevent abuse. I could use this script as a mail relay by simply setting $_POST['email'] appropriately.

4) Your HTML is badly formed. The <p> tags have no closures </p>

But none of those will stop it from working
0
 
LVL 7

Accepted Solution

by:
lexlythius earned 668 total points
ID: 35088770
Instead of discarding mail function's return value, print it:

$res = mail($to, $subject , $message, $headers);
var_dump($res);

Open in new window


If it prints false, you have a problem with the mail syntax.

If it prints true, PHP forwarded your mail to the system's Mail Transport Agent and problem is elsewhere (firewall, PHP configuration, MTA configuration, OS configuration, etc).
0
 
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 668 total points
ID: 35090825
At se point you may want to look at phpmailer. Free. Awesome. Attachments. And best of all.... Use any smut server you want. It comes with examples to pull email addresses from a db too.
0
 

Author Comment

by:brucegust
ID: 35093841
Guys, as it turns out the script does work. Because I'm on a shared server, it just took longer than I expected to arrive.

However, every one of these insights is valuable so I'm going to give all three of you points.

Thanks for weighing in!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question