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
Solved

Why doesn't this email script work?

Posted on 2011-03-09
4
239 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
4 Comments
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 166 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 167 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 167 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

790 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