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");
Related
Below is my email code written in php,program works fine but i am unable send mail to gmail.
am running my code on wamp server(web server) and am using hmail server(mail server) and squirrel mail(web mail interface)
<?php
$to = 'xyz#local.com';
$subject = 'Customer_Details Report';
$msg="php mail";
$result=mail($to, $subject, $msg);
if($result)
{
echo 'your email has been sent';
}
else
{
echo'email not sent';
}
?>
Here is how I got hMailer to work with my WAMPServer's PHP
First setup your hmailer server.
Create a domain, lets call it testmail.net
Create an account that has no password attached to it, lets say nopwd#testmail.net
Create an account that is set up as a Catch-all lets say postmaster#testmail.net. Using this you dont have to create an account for every user you want to send mail to and then login as that user, all mail comes to this account.
Now add your mail server domain name to the HOSTS file
Edit c:\windows\system32\drivers\etc\hosts and add a line like this
127.0.0.1 testmail.net
If you are running the mail server on another PC use the IP of the other PC instead of 127.0.0.1
Change the php.ini file ( use the wampmanager icon menus to make sure you are editing the correct php.ini )
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.testmail.net
; http://php.net/smtp-port
; assuming you are using the standard port number, change if you used something else.
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = nopwd#testmail.net
Now just make sure that you also use the from address when you send mail as the hmailer will want this or it will probably reject the email.
$to = 'xyz#testmail.net';
$subject = 'Customer_Details Report';
$msg="php mail";
$headers = 'From: nopwd#testmail.net' . "\r\n"
$result=mail($to, $subject, $msg, $headers);
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.
I am developing an application and have been testing the mail() function in PHP. The following works just fine on my local machine to send emails to myself, but as soon as I try to send it from the testing environment to my local machine, it silently fails.
I will still get the "Mail Sent" message, but no message is sent. I turned on the mail logging in the php.ini file, but even that doesn't seem to be populated after I refresh the page.
Again, the .php files and php.ini files are identical in both environments. Port 25 has been opened on the testing environment, and we are using a Microsoft Exchange server.
<?php
$to = "user#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "user#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
SMTP area of the php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = exhange.server.org
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = user#example.com
First of all, even when mail fails, the echo "Mail Sent." will be shown. The php function mail() will return true on success and false on failure. Put it in an if and you can check if the mail has been sent:
if(mail($to,$subject,$message,$headers)) echo "Mail Sent.";
Should be working to check if the email was sent or not.
Regarding your problem that it is not working, I am not quite sure and I might be wrong, but some servers as of my experience want the \r\n behind each headerline.
$headers = "From:" . $from . "\r\n";
But as already said, I might be wrong and related to the examples on here, it is not necessary when using one headerline - http://php.net/manual/en/function.mail.php
When I am testing the mail function, I do not put any header information into the mail function, just $to, $subject, $message. You might give it a try. I really hate using the php mail function by myown, I always use a PHP mailer class.
Sorry if I couldn't answer to your real problem, that the email can not be sent. I hope you
Check in your PHP distro for PEAR and Mail.php. On the cmd line, "php -i" to find your resources. I believe PEAR and Mail.php is fairly common for distros over 5.2. I'm on a Mac and Linux server and prefer PEAR mail over the PHP mail function. Windows should be similar. Here is an example of sending multiple emails using PEAR Mail.
/** PEAR::MAIL
* PEAR::Mail only opens one mail socket for multiple emails sent
*/
require_once('/opt/local/lib/php/Mail.php');
$body = $_POST['message'];
//using sendmail on backend
$params['sendmail_path'] = '/usr/sbin/sendmail';
//using factory method
$mail_object =& Mail::factory('sendmail',$params);
//loop through selected users to send
for ($i=0;$i<count($recipients);$i++){
if (!empty($recipients[$i]['email'])&&($recipients[$i]['alt_email'])){
//concatinate email and alt_email
$address = $recipients[$i]['email'].",".$recipients[$i]['alt_email'];
}
else {
//only one user address
$address = $recipients[$i]['email'];
}
//send the mail instance
$mail_object->send($address,$headers,$body);
if (PEAR::isError($mail_object)) {print($mail_object->getMessage());}
} //close the for loop
Some time your hosting service providers are block outgoing SMTP Authentication. Please confirm with you hosting providers.
<?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.
I am trying to get this simple php mail script to send mail to my email addres (mike_minerva#yahoo.com) and I cannot get it to work. I set my sendmail_path in php.ini to the right folder (/etc/sbin/sendmail) but that did not seem to help. What else could I be missing? The script always returns failure.
<?php
$to = "mike_minerva#yahoo.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
if(mail($to,$subject,$message,$headers))
echo "Mail Sent.";
else
echo "failure";
?>
SwiftMailer is a good library for the purpose of authenticating to your SMTP server to send mail.
http://swiftmailer.org/
try to use PEAR MAIL package.
In case anyone else comes to this question via google, another main cause of php mail not working is that the function is blocked on many servers due to the danger of outgoing spam.
There are some good smtp mail classes out there that are very easy to use. I only use mail() for debugging purposes... almost never in a live environment.