whats wrong with my php mail() function - php

Am not having good knowledge in PHP, I have just started to work on it...
Now am trying to use mail() function as example given in w3schools.com
<?php
$to = "ramkumarpece05#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "ramp211087#gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
for this am getting error message as follows
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify
your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in F:\contact.ph
p on line 7
Mail Sent.
where the php.ini file is located or i have to download it from the internet.....
Please help me to solve this issue...

You probably didn't install a mail server on your machine, you can install one for testing purposes (mail from your server will probably be marked as spam) or you can configure PHP to use your email account.

Your mail method is fine, your local server isn't. It is attempting to send the email but there is no SMTP server setup on your local server to send the email. You can install programs like Tomcat or Mercury which can handle the sending of the emails. You will just have to provide it some credentials to authenticate. I used my Gmail account's SMTP for example to send emails from my local server.

Related

Send an email using mail($to,$subject,$txt);

This is my first time trying to send email using php. I used this script which I found on W3school however it gives me the error shown below. What did I miss here?
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
mail($to,$subject,$txt);
?>
Error:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
mail() in PHP depends on an e-mail server. Without one, PHP can't send any emails.
Now, this is the important part: you can connect to a e-mail service like Gmail using SMTP to send e-mail, or have your own little local server which would usually run on localhost:25, as it tried to connect to. Some server stacks have email built in, but others not.
As the error states, you can change the addresses in php.ini or using ini_set.

Mails from PHP on XAMPP not being sent

How to send an mail from the website ..?
I am using html and php for my static website but it is not senting an mail through xamp server.... my php code is
<?php
$to = "my#domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "from#domain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
but it is not sending an email..
can anyone help me..?
It is more likely that you are trying to send mail using your local machine. You could try the following:
Open the php.ini. You should know where it is located because it depends upon the particular server you're running.
Search for the attribute called SMTP in the php.ini file. Generally you can find the line SMTP=localhost. change the localhost to the smtp server name of your ISP. And, there is another attribute called smtp_port which should be set to 25. E.g. in your php.ini file:
SMTP = smtp.mylink.com.np
smtp_port = 25
Restart the apache server so that PHP modules and attributes will be reloaded.
Now try to send the mail using the mail() function
mail("you#yourdomain.com","test subject","test body");

how to send email from Apache server by PHP script

I have installed Apache and PHP on my Windows 7 PC. I learning the PHP now. Following is my PHP script to send email.
<?php
if(isset($_REQUEST['email']))
{
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
mail("padhy.surya#gmail.com","$subject","$message","From:","$email");
echo "Thank you for using the email !!!";
}
else
{
echo "Mail is not set properly. Please fill the form properly";
}
?>
I am using a html form to get the required parameters for sending email. Following is the error I am getting while I send the email.
Warning: mail() [function.mail]: Failed to connect to mailserver at
"localhost" port 25, verify your "SMTP" and "smtp_port" setting in
php.ini or use ini_set() in
C:\WebLearn\Apache-2.2\htdocs\SimpleWebsite\contact.php on line 7
Do I need to set anything to set in php.ini file or in httpd.conf? If yes how to configure it? Do I need an additional SMTP server on my PC to send email? Please suggest the necessary steps to send an email from my local PC.
The message is saying that it's trying to deliver the email to localhost:25, and there's nothing listening there.
PHP cannot email "the Internet" directly. The message must go to a mail server program such as Postfix or Sendmail or SSMTP, which then relays it to the appropriate destination.
You must install and configure a mail server program and set PHP to use it via php.ini. I believe you also have the option of configuring PHP to use a Sendmail binary instead of SMTP delivery.

What does the below Warning mean?

<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
When I run these script I get these error
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost"
port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
in C:\xampp\htdocs\website\mail.php on line 7
What I have to do now? Could anyone tell me the way to do it ? Okay I have found that file but what are the fields I need to update could you suggest me some code so that i paste it these and save?
You have to configure your php.ini with a valid smtp server and email address.
You need to configure PHP to use a working SMTP service in order to send SMTP email. Here's an article that discusses the subject.
Basically, it appears that the SMTP configuration for your PHP instance is using default values, which point to localhost. But your local computer doesn't seem to be running an SMTP service. So you'll need to point is to a server that is running one, and one which your application is permitted to use.
I guess that this question is the same as your other question...
If so, I guess you are trying to send an email through GMail's SMTP server. Their server requires authentication, which PHP's mail function doesn't support.
As I answered you in the other question, you can use Zend_Mail to do this. You can also use PEAR Mail like in the example in the other question.
Either way you will need to download some external file, include it in your code and use it.

Problem with Free SMTP Server in php code

I wrote php code for use to contact us form
but I can not find free SMTP server to use it.
I Try to use SMTP Server For Gmail but I found this error.
Warning: mail() [function.mail]:
"sendmail_from" not set in php.ini or
custom "From:" header missing in
C:\www\htdocs\contactUs.php on line
25"
line 25 is :
mail ($to,$subject,$body,$headers);
statement that indicate using Gmail SMTP Server is :
ini_set("SMTP","smtp.gmail.com");
SO,can U help me ?:(
You need a From: [VALID EMAIL] header of the message when you send the message. Try doing something like this:
$headers = array(
'From: me#example.com',
'Mime-Type: text/plain; charset=utf-8',
);
$dest = 'some_user#example.com';
$subj = 'test';
$message = 'hello world';
mail($dest, $subj, $message, implode("\r\n", $headers));
Also, the mail function is meant to be used as a frontend to the mail daemon that's running on the same server the web server is running on. Since most *NIX boxes have both, it usually works.
What I would not recommend, however, is using some remote server to send your mail. It's much more efficient and reliable (not to mention looking more professional) to just have the same server send the message as the one that generated the message.
Setting up your own SMTP server is easy and free and more flexible than Gmail. Gmail WILL NOT send messages whose From: header does not match either the main account address or a connected address.

Categories