Solved

PHP Email Script not Sending Emails

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

630 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