Solved

PHP Email

Posted on 2013-06-18
8
400 Views
Last Modified: 2013-06-19
Hello,

I am new to PHP. Thru a search from Google, I copied this code, and tried to test email thru web.

Request you to kindly let me know what is the error in this program. It is not sending the mail.

Sanjay.
MailThruPHP.php
0
Comment
Question by:sanjay-gandhi
[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
8 Comments
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39255972
Here is the PHP script.  When you post code at EE, please use the code snippet feature.
<?php
 $to = "to@email.com";
 $subject = "Test mail";
 $message = "Hello! This is a simple email message.";
 $from = "from@email.com";
 mail($to, $subject, $message, $from) or die("failure");
 echo "Mail Sent.";
 ?> 

Open in new window

If you're new to PHP, this article will help you get started.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

There are many things that can go wrong with email.  For example, in this script the "to" address is undoubtedly wrong.  There are DNS settings to consider.  There are spam filters that may intercept the messages.  

You say that the mail is not sent.  How do you know this?  Can you distinguish "not sent" from "not received?"  Do you have the server configured correctly to send mail?

Email is very complicated at this level and your learning experience with PHP might go better if you started with something simpler than email!
0
 

Author Comment

by:sanjay-gandhi
ID: 39256145
Thanks, I will find the code snippet feature.
I am using Xampp. I 've configured Xampp, and in htdocs folder, I've tested other small PHP programs. In the To variable, I've put the actual Email-ID. And also in the From variable, I've put another Email-ID.
However, I will look at the link above to see if I can reach the solution. I will need to know how to do DNS settings.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39256203
One of the common issues I have found arises if the correct mail extension program is not in place.  Check the pages linked here.
http://php.net/manual/en/refs.remote.mail.php

Another common issue is that the server's internal DNS pointers may not route messages to the internet if the internal DNS sees a "to" address that matches its internal DNS records.  This is often a problem when the client is trying to use a regular email program (outlook, etc) to read the messages.
0
Independent Software Vendors: 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!

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39256637
You have a web server configured, but what are you using as the SMTP server.  To send mail you need a mail server to handle the traffic generally on port 25.

Cd&
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39257210
The Mercury mail server that comes with XAMPP will Only send from email addresses created on that machine.  It will refuse to send 'from' outside email addresses.  I found Mercury to not be very useful and not what you would expect on normal hosting.
0
 
LVL 1

Accepted Solution

by:
svenove earned 300 total points
ID: 39258639
If you've installed XAMPP on your Windows-machine, you need to configure email-settings for PHP to be able to send emails.

Here's how to do it for sending through Gmail, just adjust to your own providers settings:
http://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/
0
 

Author Closing Comment

by:sanjay-gandhi
ID: 39258882
Thanks Svenove,

That answer just hits the question. Though I had Rediff settings for which the SMTP Port is 587 which worked fine.

Thanks Ray_Paseur,

This reading is very helpful. Will need it for more time to come.

- Sanjay.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39259096
Thanks for the points and best of luck with your project, ~Ray
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Session time out quickly. 6 54
A responsive image gallery using flexbox 6 78
php mail() send emails but the message is lost 4 33
php time 12 25
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.

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