Solved

PHP Email

Posted on 2013-06-18
8
394 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
8 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
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 108

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

7 Experts available now in Live!

Get 1:1 Help Now