Solved

PHP Email Script not Sending Emails

Posted on 2011-02-24
4
260 Views
Last Modified: 2012-08-13
Hi,

Just trying to get some very basic PHP code to work to send an email.

This is copied from the W3C schools website.
It doesn't work - no emails arrive - I don't get any failure and no error codes but no email either.
$to = "name@mydomain.co.uk";
$subject = "Enquiry from Website";
$from    = "info@mydomain.co.uk";
$message = "Hello you! This is a simple email message";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: $from" . "\r\n";

mail($to,$subject,$message,$headers);

echo "Test eMail Sent";

Open in new window

0
Comment
Question by:Sean Clarke
  • 2
4 Comments
 
LVL 38

Expert Comment

by:Aaron Tomosky
ID: 34971308
Yourailserver has to be setup in php for this to work. Try phpmailer
0
 
LVL 17

Expert Comment

by:psimation
ID: 34971574
Examples of using PHPMailer class here: phpmailer.worxware.com/
Download it here: sourceforge.net/projects/phpmailer/
More examples/tutorials here: www.askapache.com/.../phpfreaks-eric-rosebrocks-phpmailer-tutorial.html

The built in PHP mail() function is dependent on a working smtp setup on your server, usually sendmail. Even if the smtp server is configured, there are hundreds of reasons why a mail using mail() may not reach it's intended target.

PHPMailer class allows you to utilize an existing smtp server ( like the one you get from your ISP or Hosting Provider).

You also have much much more control over your mail.
0
 
LVL 4

Expert Comment

by:racastillojr
ID: 34974595
$to = $_POST["to"];
$from = $_POST["from"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html;charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding:7bit\r\n";
$header .= "From:". $from . "\r\n";
$mailsent = mail("user@email.com",$subject,$from,$message,$headers);

this code is pulling fields from a email form.
0
 
LVL 4

Accepted Solution

by:
racastillojr earned 500 total points
ID: 34974636
This has to be sent from a server not local host to work
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Testing a string condition in PHP 6 22
Insert values are dynamic 11 41
Which userID to use for shopping cart application 13 19
How do I fix this UPDATE error? 7 24
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

777 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