i want to send email using php through xampp server.here is my code
<?php
$to = 'atchibabu#solbaacken.com';
$subject = 'My Email';
$msg = "please find details";
// Make sure to escape quotes
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <atchibabu516#gmail.com.com>' . "\r\n";
if(mail($to, $subject, $msg, $headers))
{
echo "success";
}
else
{
echo "fail";
}
?>
when i execute i get "success" message but i didn't get any mail i am waiting still one hour
i don't know why it's happening. some suggestions send email using smtp so can any one guide how could i use the smtp.i am using mac xampp so any one guide me i could i install smtp in mac xammp.
thanks for advance.
Few things to note:
Your from has 2 .com so, probability of your message going in SPAM is almost 90%.
Check your phpinfo(); output. What does sendmail_path show? Do you have that software installed? Ideally it is /usr/sbin/sendmail -t -i and the software is sendmail in ubuntu machines.
Also, in your phpinfo(), check the SMTP port. Also there is a high possibility of getting blocked by a firewall or similar software, checked it already?
You should configure your email on localhost
here is the step by step way to configure your smtp
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.I’ve set the following values in my php.ini file.
SMTP = smtp.wlink.com.np
smtp_port = 25
Restart the apache server so that PHP modules and attributes will be reloaded.
Now try to send mail
Reff link is here
helpfull links
http://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/
Edit your SMTP. If you want to test it in your localhost, try installing Mozilla Thunderbird for localhost email and create new account using Mercury from Xampp.
Related
I am designing a contact form on a website and despite all the tutorials that I followed online to get it to work, it just isn't working.
I am currently using XAMPP for Windows and I know that I need to change my php.ini and sendmail but no matter how much I change my SMTP settings, I just cannot get the contact form to work.
Could someone please give me an up-to-date explanation of how this whole procedure works?
I am planning to put the website online eventually. When this comes, I suppose the php.ini and sendmail file from XAMPP won't matter anymore right? So how does it work on a web server?
Thanks
Don't forget to set a valid smtp in your php.ini because sendmail is not used on Windows.
Use your ISP's smtp.
Your php.ini wont work on webserver.
On webserver most time, the emails are handled by their smtp relays. So do not worry about emails in webserver. For testing you just upload your email script on webserver at any address, and test it it works.
Here I am providing you code which should work on your webserver.
$To = "email address of person whom you want to send email";
$From = "your email address";
$Subject = "subject of email";
$Email = "your message";
$Headers = "MIME-Version: 1.0" . "\r\n";
$Headers .= "Content-type:text/html; charset=iso-8859-1" . "\r\n";
$Headers .= "From: " . $From . "\r\n";
$mail = mail($To, $Subject, $Email, $Headers);
if ($mail) {
echo "email sent";
} else {
echo "email failed";
}
You can also use an remote SMTP server, such as Gmail, to test the email sending locally. This avoids the need to have an email server configured in the current environment.
After you get your code on the server, you should then change the configurations to use the webserver email server.
How can i send an Email using PHP at windows Azure?
i am using simple mail function:
$to .= 'email-Id';
$subject = " Test Subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$to.'' . "\r\n";
$headers .= 'From: '.$name. '<'.$email.'>' . "\r\n";
echo $message='email text here';
#mail($to, $subject, $message, $headers);
To send emails using PHP you have a few options:
Option 1: Use SMTP
You'll need to modify your php.ini configuration file (http://php.net/manual/en/ref.mail.php) and set the SMTP value to an external SMTP server you can use. SMTP servers are not part of the Windows Azure features at the moment.
[mail function]
SMTP = mail.mycompany.com
Option 2: Use sendmail
You'll need to modify your php.ini configuration file (http://php.net/manual/en/ref.mail.php) and set the sendmail_path value to the sendmail executable.
[mail function]
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Since sendmail doesn't exist in Windows, you'll need to use the fake sendmail for windows: http://glob.com.au/sendmail/
Option 3: Use a mail/smtp service
You could use a service like SendGrid to send your emails (they have an offer for Azure users: http://sendgrid.com/azure.html). They'll take care of sending out the email, you'll just need to call the REST api:
$sendgrid = new SendGrid('username', 'password');
$mail = new SendGridMail();
$mail->addTo('foo#bar.com')->
setFrom('me#bar.com')->
setSubject('Subject goes here')->
setText('Hello World!')->
setHtml('<strong>Hello World!</strong>');
$sendgrid->smtp->send($mail);
I had never done PHP, but the following guide was step by step and incredibly easy to get working.
http://www.windowsazure.com/en-us/Documentation/Articles/store-sendgrid-php-how-to-send-email/
Hope it helps someone.
email-Id ?? what is this?
I'm guessing it is the email address of the recipient.
Your headers do not require the To: as the to address is specified in the first parameter.
Unless you know the recipient's name and want him to see email was sent to: Some Name not just you do not need that.
Also you have an error in it: missing <> before and after the email address.
P.S. Emails sent through PHP's mail() function have one of the highest rates of ending up in SPAM, especially if you do not have Domain Keys and SPF set in your DNS for this.
If using Cpanel please refer to Email Authentication section of your Email group in Cpanel.
I was having the same trouble , but this solution works perfectly for me .
just follow these steps :
Just enable 2 step verification on your G-mail account.
Go to app password and then select app = other and then type AzureWebsite and generate a password , and keep the password.
replace the
$mail->Password = 'new password';
4.I hope this will work for you too .
Updated information # Nov-2017:
Full Blog post:
https://blogs.msdn.microsoft.com/mast/2017/11/15/enhanced-azure-security-for-sending-emails-november-2017-update/
Recommended Method of Sending E-mail
"Microsoft recommends that Azure customers employ authenticated SMTP relay services (typically connected via TCP port 587 or 443, but often support other ports too)....."
I am new to PHP and I'm using the mail function to send emails which is not working. I get a success message, but still it does not work
same code
<?php
$email_to = "abc#abc.com";
$email_subject = "Test mail";
$email_body = "Hello! This is a simple email message.";
if(mail($email_to, $email_subject, $email_body)){
echo "The email($email_subject) was successfully sent.";
} else {
echo "The email($email_subject) was NOT sent.";
}
?>
Am I missing anything, do I need to include any files for this function.. I am from asp.net & this is the basic script which found on website.
I tried other scripts related to mail they didn't work either..
I AM RUNNING THIS SCRIPT ON THE WEBSITE NOT on the localhost
If you are using Ubuntu and it seem sendmail is not in /usr/sbin/sendmail, install sendmail using the terminal with this command:
sudo apt-get install sendmail
and then run reload the PHP page where mail() is written. Also check your spam folder.
This is probably a configuration error. If you insist on using PHP mail function, you will have to edit php.ini.
If you are looking for an easier and more versatile option (in my opinion), you should use PHPMailer.
This might be the issue of your SMTP config in your php.ini file.
Since you new to PHP, You can find php.ini file in your root directory of PHP installation folder and check for SMTP = and smtp_port= and change the value to
SMTP = your mail server e.g) mail.yourdomain.com
smtp_port = 25(check your admin for original port)
In case your server require authentication for sending mail, use PEAR mail function.
"Just because you send an email doesn't mean it will arrive."
Sending mail is Serious Business - e.g. the domain you're using as your "From:" address may be configured to reject e-mails from your webserver. For a longer overview (and some tips what to check), see http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
The mail function do not guarantee the actual delivery of mail. All it do is to pass the message to external program (usually sendmail). You need a properly configured SMTP server in order for this to work. Also keep in mind it does not support SMTP authentication. You may check out the PEAR::Mail library of SwiftMailer, both of them give you more options.
Check your SMTP settings in your php.ini file. Your host should have some documentation about what credentials to use. Perhaps you can check your error log file, it might have more information available.
For HostGator, you need to use the following for your headers:
$headers = 'From: user#yourdomain.com' . " " .
'Reply-To: user#yourdomain.com' . " " .
'X-Mailer: PHP/' . phpversion();
It only worked for me when the from user was host e-mail while the Reply-To can be something different e.g. From: owner#domain.com, Reply-To: info#domain.com
http://support.hostgator.com/articles/specialized-help/technical/php-email-from-header
http://support.hostgator.com/articles/specialized-help/technical/how-to-use-sendmail-with-php
The php mail function has stopped working on a Centos 5.7 server. The scripts containing the function call were working on this server until the last couple of days but there have not been any configuration changes..
Whenever I call the mail() function the PHP script just stalls/freezes on that line until it reaches the script timeout limit.
$msgheader = 'MIME-Version: 1.0' . "\r\n";
$msgheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$msgheader .= "From: Test Name <no-reply#servername.com>\r\n";
echo "About to send mail ->";
mail ("test#servername.com", "Test Subject", "Test Body", $msg_header);
echo "Script never reaches this line!";
I have modified the email addresses for this question, but I know they are not the issue as the script executed correctly previously.
I have tried changing the email address to various personal accounts (e.g. #yahoo.com) and it still doesn't work, so I don't think this is due to spam filtering at the organization where my users reside.
What could be causing the mail function to get stuck until the script timeout rather than just immediately return false if it can't send the email? What settings can I look at?
Thanks!
EDIT:
There are no errors in the Apache error logs
php.ini has:
SMTP = localhost;
smtp_port = 25;
sendmail_path = /usr/sbin/sendmail -t -i
This issue was related to a problem with the DNS settings of the server.
After attempting:
yum update
it became clear the server was having an issue connecting to the internet. This explains the long timeouts attempting to make the outbound connection to send the email.
I had to add
search localdomain
to my /etc/resolv.conf file in CentOS to establish the outbound connection. This question was better posted on ServerFault now that I know that issue.
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("example#gmail.com", "hello", "nothing",$headers);
echo "mail sent";
?>
but it does not actually send the mail please help me out with this
The mail function is just an interface to the local mail server. The mail functionality in PHP relies on the machine PHP is running on to be correctly configured and able to dispatch e-mail. Check the mail system configuration on the machine.
check the following -
check if your smtp server is running (you could either check through command line tools or try ftp'ing to port 25).
If your smtp server is running. Then try to send a mail manually (without script). Use the command-line mail command (I am assuming you have unix here).
Also, when you run your script, what happens? It could be possible that your mail is in a Queue. From your terminal type 'mailq'. This shows the current emails in Queue & why they are there. Also there is a corresponding log to this. You could also check that out for info.
My guess is if all the above are running, you are good to go.
please check following ** Please verify your servers sender domain policy**
Emails sent through your servers (mail servers and shared web servers) should use a from address that is hosted here at your server. Emails that are sent with a from address hosted somewhere else (like Hotmail or Google) may be blocked.
ie use
$header = "From:example#/*yourhostname.domain name*/ \r\n";