[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Why doesn't this email script work?

Posted on 2011-03-09
4
Medium Priority
?
260 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

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
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

656 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