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)....."
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I am creating a login page.For that, after the signup I need to send the mail to the user for verification.Therefore, I need to send mail.To send the mail, I tried with mail() function like this,
<?php
//sending email with the php mail()
mail('mahadev.3333#gmail.com', 'Subject Line Here', 'Body of Message Here', 'From: vidya.5555#gmail.com');
?>
I have configured php.ini file also like below,
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from ="vidya.merahkee#gmail.com"
I am using windows 64-bit.
And also I have tried with phpmailer. But,I didn't find any solution.Since, 2 day I am trying this.I am unable to do this one.
Can anybody help me to solve this?
First of all if you are using the script on production server then ask your admin for the mail function is active or not . Some time on production server it's blocked by Site admin.
Second if you are using this script on localhost server means on your desktop then first you have to use the mail server start.
for example i am considering that you are using XAMMPP on windows then Your have to start the Mercury Mail Server From the XAMPP control panel.
Mercury by default comes with postmaster and newuser two users.
Then You have to download Mozilla Thunderbird mail client and configure the
newuser and postmaster user in mail client by following the Create New account > email using the newuser#localhost and manually configure the pop and smtp server and port . usually default ports.
you can use the sendmail_from ="newuser#localhost"
then check Mercury Mail server is running then test your script.
it will send the mail and you then check it in the Mozilla Thunderbird mail client.
Third : for setting the From: you have to use the header like below
$headers = "From: newuser < newuser#domain.com >\n";
<?php
$send_to = 'postmaster#localhost';
$mail_subject = 'Subject of Your mail';
$message_body = 'Body of your email like message form php script.';
$headers = 'From: newuser#localhost' . "\r\n";
mail($send_to, $mail_subject, $message_body, $headers);
?>
I hope this will solve the problem .
NOTE if you want to send email form localhost to gamil or any other mail site then you have to use the sendmail application or more tutorial Search the google Term like 'Send email via Gmail in PHP '
I use adsl net and iam from Nepal.
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.ntc.net.np
; http://php.net/smtp-port
smtp_port = 25
Why email is not working?
Your SMTP configuration is ok! Seems like you have miss headers. Don't worry here is full description and examples
For ADSL Internet
SMTP = smtp.ntc.net.np
For WorldLink Internet
SMTP = smtp.wlink.com.np
For Example (FOR WORLDLINK)
1) Open the "php.ini".
2) Search for the attribute called "SMTP" in the php.ini file.
SMTP = smtp.wlink.com.np
smtp_port = 25
3) Restart the apache server so that PHP modules and attributes will be reloaded.
4) Now try to send the mail using the mail() function ,
mail("you#yourdomain.com","test subject","test body");
you might get the warning like this, for not including headers
5) Now specify the following headers and try to send the mail again,
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: sender#sender.com' . "\r\n";
mail("you#yourdomain.com","test subject","test body",$headers);
Remember to includes headers otherwise you will get error message :)
1) Open the “php.ini“. You should know where it is located because it depends upon the particular server you’re running.
2) 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
3) Restart the apache server so that PHP modules and attributes will be reloaded.
4) Now try to send the mail using the mail() function ,
mail(“you#yourdomain.com”,”test subject”,”test body”);
you might get the warning like this,
*Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1*
5) Now specify the following headers and try to send the mail again,
$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From: sender#sender.com’ . “\r\n”;
mail(“you#yourdomain.com”,”test subject”,”test body”,$headers);
Well that’s all, the mail is sent to “you#yourdomain.com” from the localhost.
Note : Some smtp server verifies the email address of the sender so the email address which is in the place of “sender#sender.com” should be a valid and existing email address otherwise mail might not be sent to the “you#yourdomain.com”.
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.
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
I am sending mails from my website by using php mail function. But now it is not working and I contacted our hosting team then they told me to use smtp as they did some changes in server. I don't know how to do it. Current code (with php mail function) is as follows, can anyone help me about the changes which I have to do with this.
<?php
$mail_To="someone#gmail.com";
$headers = "";
$headers .= "From: livetv#muscle-tube.com\n";
$headers .= "Reply-To: livetv#muscle-tube.com\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Mailer: php";
$mail_Subject = " Live TV key";
$mail_Body = "<p>Muscle-tube</p>";
mail($mail_To, $mail_Subject, $mail_Body,$headers);
?>
PHP's mail() function does not have support for SMTP. You're going to need to use something like the PEAR Mail package.
Here is a sample SMTP mail script:
<?php
require_once("Mail.php");
$from = "Your Name <email#blahblah.com>";
$to = "Their Name <otheremail#whatever.com>";
$subject = "Subject";
$body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit...";
$host = "mailserver.blahblah.com";
$username = "smtp_username";
$password = "smtp_password";
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if ( PEAR::isError($mail) ) {
echo("<p>Error sending mail:<br/>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message sent.</p>");
}
?>
Note that PHP mail settings come from your php.ini file. The default looks more or less like this:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me#example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log =
By editing your php.ini file you should be able to fix the problem without changing your PHP scripts. Also, you can test a connection with the telnet tool and the HELO, MAIL FROM, RCPT TO, DATA, QUIT commands if you directly connect to an SMTP server. With sendmail, you don't even need that, sendmail should know what it's doing (although in your case it probably wasn't and the sendmail settings probably needed a little help.)
Update: in most cases, telnet is not installed anymore because it's considered dangerous (i.e. it gives you a clear text connection which is generally fine on your local network, but not so much to remote computers). Instead, we have nc which is very similar for testing things such as SMTP but doesn't really allow for remote shell connections. That being said, more and more SMTP is going to use encryption as well so the best tool to test is still sendmail.
Since some of the answers give here relate to setting up SMTP in general (and not just for #shinod particular issue where it had been working and stopped), I thought it would be helpful if I updated the answer because this is a lot simpler to do now than it used to be :-)
In PHP 4 the PEAR Mail package is typically already installed, and this really simple tutorial shows you the few lines of code that you need to add to your php file http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
Most hosting companies list the SMTP settings that you'll need. I use JustHost, and they list theirs at https://my.justhost.com/cgi/help/26 (under Outgoing Mail Server)
But now it is not working and I contacted our hosting team then they told me to use smtp
Newsflash - it was using SMTP before. They've not provided you with the information you need to solve the problem - or you've not relayed it accurately here.
Its possible that they've disabled the local MTA on the webserver, in which case you'll need to connect the SMTP port on a remote machine. There are lots of toolkits which will do the heavy lifting for you. Personally I like phpmailer because it adds other functionality.
Certainly if they've taken away a facility which was there before and your paying for a service then your provider should be giving you better support than that (there are also lots of programs to drop in in place of a full MTA which would do the job).
C.
php's email() function hands the email over to a underlying mail transfer agent which is usually postfix on linux systems
so the preferred method on linux is to configure your postfix to use a relayhost, which is done by a line of
relayhost = smtp.example.com
in /etc/postfix/main.cf
however in the OP's scenario I somehow suspect that it's a job that his hosting team should have done