Solved

PHP Email

Posted on 2013-06-18
8
402 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
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!

 
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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 …

636 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