Solved

PHP Email Script not Sending Emails

Posted on 2011-02-24
4
272 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
[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
  • 2
4 Comments
 
LVL 39

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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