i am trying to use phpMailer to send confirmation messages to users via email. my code is this:
$SMTP_USERNAME = SMTP_USERNAME;
$SMTP_PASSWORD = SMTP_PASSWORD;
$SMTP_HOST = SMTP_HOST;
$SMTP_STATUS = SMTP_STATUS;
if($SMTP_STATUS==1)
{
include($_SERVER['DOCUMENT_ROOT']."/modules/SMTP/smtp.php"); //mail send thru smtp
}
else
{
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: '.$from.'' . "\r\n";
$headers .= 'Bcc: '.$to.'' . "\r\n";
mail($from,$subject,$message,$headers);
}
but every time I load it, it displays this
Error msg: " SMTP Error: Could not authenticate.
Please help me out from these issue.
Thanks for your time guys, hope someone can get back to me soon!
The mail() function does not allow any kind of authentication. You need to switch to a third-party mail package that implements the required SMTP authentication (or write you own, which I wouldn't recommend). Typical choices include:
PEAR Mail
PHPMailer
Swift Mailer
Related
How we can a Send a email using PHP mail function to gmail archive mail folder?
My code
$to = "myemail#gmail.com";
$subject = "Subject" ;
$message = 'Example message with <b>html</b>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: xxx <xxx>' . "\r\n";
mail($to,$subject,$message,$headers);
Note:
Smile email/mail function is fully functional but I want to send mail to gmail archive folder directly.Is there any way to do that?
It depends on the recipient's e-mail settings, you can't do that on the sender side.
I have a function in my wordpress site, and its working.
function wp_send_email_shipping_confirmation( $args ){
$content = send_email_shipped_confirmation( $args );
$headers[] = 'MIME-Version: 1.0' . "\r\n";
$headers[] = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers[] = "X-Mailer: PHP \r\n";
$headers[] = 'From: Wristband Creation Team <no-reply#' . $_SERVER[HTTP_HOST] . '>' . "\r\n";
$mail = wp_mail( $args['email'], 'Your Wristbands Has Shipped Out', $content, $headers );
}
in my local server(mamp pro) i can receive it on gmail and the sender is no-reply#mydomain.com and that is working.
but when i uploaded it on my host(Bluehost) the email function is working fine aside from the sender it looks like this (myhostID)#box421#bluehost.cominstead of no-reply#mydomain.com
Hosting provider does not allow you to send email this way.
If you really want to send email from this account (no-reply#mydomain.com) you should create SMTP account in your domain and send mail through that using SMTP plugin, not wp-mail function.
The mail() function in PHP works fine when sending to Gmail if I don't specify any headers. However, as soon as I try to add in headers, the function still returns true but I never get the email. The Gmail server seems to reject the delivery.
These are the headers I'm using:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $username . ' <' . $email . '>' . "\r\n";
$headers .= 'From: Blahblah <email#example.com>' . "\r\n";
mail($email, 'Subject', '<html><body>Body of message</body></html>', $headers);
I was hoping that someone could point out to me the flaw? I grabbed most of this code straight from the PHP manual, so one could understand my confusion and frustration. Thanks!
The bigger email services will not deliver mail sent from your own personal server in this manner.
Due to SPAM issues. All the big mail providers require SPF records, DKIM, and reverse DNS before they will accept your mail.
Some live/hotmail user's are not receiving html mail
Personally I prefer to be rid of that hassle and use a 3rd party mail server for all of my outgoing mails to my users.
$Headers .= "From: $Yourname <$YourEmail>\r\n";
or
$Headers .= 'From: '.$Yourname.'<'.$Youremail.'>'."\r\n";
or
$Headers .= 'From: '.$Yourname.' <".$Youremail.">' . "\r\n";
Give a try if any of this work?
Mail function now not working my server. i cannot find out the solution for that. i am getting bellow this error when i submitting the contact form.
Warning: mail() [function.mail]: SMTP server response: 550 Sender is not allowed. in E:\HostingSpace\abayamtranslations.com\httpdocs\contact-form\classes\contact.php on line 137
ERROR! Please ensure PHP Mail() is correctly configured on this server.
$address = "info#abayamtranslations.com";
ini_set("SMTP","mail.abayamtranslations.com");
ini_set("smtp_port","25");
ini_set('sendmail_from','info#abayamtranslations.com');
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
Try with the following
$emailFrom = "info#abayamtranslations.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Subject of email";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Message of email";
mail($email, $subject, $message, $headers);
"550 Sender is not allowed" means that the SMTP Blocked Senders list rejected the sender. Search your SMTP log for 550 Sender is not allowed and figure out what address is getting blocked and then alter your list to let that through.
That is the meaning of the error you are getting. This is from the hMailServer Documentation.
Can you try if the following will work?
<?php
mail('info#abayamtranslations.com','Test Email','This is a test email.',"From: info#abayamtranslations.com");
?>
If it doesn't work, then it's probably due to a misconfiguration in your hMailServer and you would need to check your hMailServer Logs.
You are on the windows server, hence forth you have to change SMTP of windows server.
Better way is to use PHPMailer Library. https://github.com/PHPMailer/PHPMailer
Some important information is missing under your SMTP configuration....
username and password is needed to authenticate with the SMTP mail server.....
it easy ti use smtp mailing in php with:
PHPMailer (https://github.com/Synchro/PHPMailerhttps://github.com/Synchro/PHPMailer)
have a look into it....
Thankyou....
I am using following php code but i ain't getting any mail
function Mail($to, $subject, $message)
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: MYAPP! <myYahooMail>' . "\r\n";
// Mail it
if(!mail($to, $subject, $message, $headers)) {
throw new Exception('There was a problem trying to send an email.');
}
}
The error you're getting is Fatal error: Cannot redeclare mail(). This is because
PHP has a built in mail function. Name your function something else.
You probably need to edit your php.ini (xampp\php\php.ini). Search for "mail function" and change these parameters according your server specs. If you are not the host, you can do this via htaccess.
SMTP = "Your server smtp address here"
smtp_port = 587