Solved

PHP Email Script not Sending Emails

Posted on 2011-02-24
4
256 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now