wp_mail() method not sending email in some cases - php

That is my code for sending email via wp_mail() method
$user_email = $_POST["user_email"];
$subject = 'Account is ready.';
$message = "Hello <b>$user_name</b>,a new account created for you and you need to create a password, <a href'http:example.com/account?email=$user_email'>click here</a> to create a password and login.";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$mail = wp_mail($user_email, $subject, $message, $headers);
if($mail){
echo 'Sent email to user.';
}
else {
echo 'Oops something went wrong to sending email.';
}
actually that didn't work I mean not sending the email to user, while modify the wp_mail() method like this
$mail = wp_mail($user_email, $subject, $message);
that's working, that the mean it never taken more than three parameters, but I need to add $headers for HTML.
What can I do now?
Any advise?
Thanks

According to the wp_mail docs the headers parameter is used to set From, CC and BCC fields. It might not set other fields.
To set your content type and character set you need to use another function, please see linked docs.
Mail is send in plain text by default, to send it as HTML you should also consult linked docs as the method to switch to HTML is also there.

Have you setup, SMTP settings in WordPress panel if not you can use Many plugins to setup you can use m fav plugin
https://wordpress.org/plugins/post-smtp/
Try to set up this plugin and after let me know if you still facing those issues

Related

How add List-Unsubscribe header to native mail() function of PHP

i've tested my spamscore on https://www.mail-tester.com/. It was good, but as an aprovement it suggested :
Your message does not contain a List-Unsubscribe header The
List-Unsubscribe header is required if you send mass emails, it
enables the user to easily unsubscribe from your mailing list.
How do I add this to a native mail(); function of PHP. Or is it even possible this way? (I cannot find one single simple example on the www).
You can add additional headers with the mail() function.
$headers = [
'From: thisisme#example.net',
'List-Unsubscribe: <mailto:thisisme#example.net?subject=unsubscribe>'
];
$body = 'I am the newsletter content.';
mail('recipent#example.net', 'Subject of newsletter', $body, implode("\r\n", $headers));

Configuring PHP to Function with SMTP

I have a register script that sends an email to who ever signs up.
//// Set headers ////
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= "Content-type: textrn";
$headers .= "From: $from";
/// Send the email now ////
mail($email1, $subject, $message, $headers, '-f nleachman#stayontrack.net');
//mail($email1, $subject, $message, $headers, '-f noreply#your-email.com');
$db->commit();
echo "Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!";
$db = null;
exit();
}
catch(PDOException $e){
$db->rollBack();
echo $e->getMessage();
$db = null;
exit();
}
Here is my SMTP server used for configuration:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = nleachman#stayontrack.net
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
When ever I try to run my log-in script I get this:
Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!
My problem is that who ever signs - up never recieves the email. At first I thought that it may just be an impossible function on localhost. Then however, I saw some codes that worked for other people but gave me an error like...
Variable $From not set
How could I configure my code so that it runs without errors?
Also, how could I configure the code to make sure who ever the email is sent to recieves it?
For using SMTP within PHP, you should have a look at phpmailer. https://github.com/Synchro/PHPMailer
easy to configure and does all the work for you.
You're using mail() to send the email - I've had problems with this before not sending to certain domains like hotmail. I'd give PEAR mail a go - http://pear.php.net/package/Mail/redirected.

PHP mail function is not working for Webform

Below is the Webform PHP code I used for e-mail function. After I click the SUBMIT button in the form, I am successfully getting redirected to the thankyou.html page but I don't get any e-mail to my e-mail account. Kind help is deeply appreciated.
PHP Code:
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
mail('myemail#email.com', 'Subject Line', $emailbody);
header('location: thankyou.html');
} else {
header('location: index.html');
}
?>
You may be missing the "From" field in the $additional_headers argument. Try
$headers = 'From: myemail#email.com';
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
It might be a problem with your host.
I think due to the email spams that #email.com got from your host it may be now in the blacklist.
This means you have to contact your host about this problem and tell them to talk with #email.com to remove your host from the blacklist.
I had this problem a while ago on 000webhost.com and they told me i can't send emails to an yahoo.com account because yahoo.com added the 000webhost.com on the blacklist because users spammed the Yahoo servers.
It's likely that your server, or one along the route, is refusing to deliver the mail because it has no From: address. You can add one using the headers parameter for mail():
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
// Add extra headers here
$headers = "From:address#examle.com"
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
header('location: index.html');
} else {
header('location: about-us.html');
}
You should check any user-suplied input to ensure it doesn't try to subvert your mail function by adding headers of its own. Check for text like To:, Cc: or Bcc:.
Most ISPs will refuse to deliver email unless it comes from a domain registered with them. Sometimes the from address must exist on the server generating the mail.
Note that there are other reasons why mail might not be delivered: bad addressing and spam filters to name but two.
I found the answer. I just changed $emailbody into $message and it is working fine now. I am not sure that using $emailbody instead of $message was the issue but it is working fine now.
Thank you all.
First check your hosting server is that providing mail functionality for this you just write
echo phpinfo();
you need to check the mail function enable or not

HTML Tags are not rendering in the Gmail - Using PHP language

I have used used the PHP Language for Sending the email and HTML tags are not rendering in the gmail account sometimes.I have used Content Type as - charset="iso-8859-1" I have attached the image.
And also am receiving the Message ID, which should not be come in the mail.
I don't recommend/use php built in mail() function to send and receive emails. Use php open source libraries like PHPMailer and SwiftMailer. I have been using PHPMailer after facing many issues when using mail() alone. Very easy to implement and has lots of features. You don't have to spend your valuable time for email sending related development.
http://phpmailer.worxware.com/
http://swiftmailer.org/
If the HTML isn't rendering, that usually means the headers weren't set properly.
Try this:
<?php
//change this to your email.
$to = "m#m.com";
$from = "m#m.com";
$subject = "This is HTML email";
$message = "
<b>htmlemail....</b> <br>
<a href='http://www.google.com'>Google</a>";
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
mail($to, $subject, $message, $headers);
echo "Message sent..";
?>
From http://www.webhostingtalk.com/showthread.php?t=416467

PHP mail function can't send out email when I added .com.sg instead of just .com

I want to send out a link for user to verify their account after they register. But when I use www.singapore.com at the $message I am able to receive the email, but when I change it back to www.singapore.com.sg I can't receive it. I wonder is it because of the link or there is some error in my codes? Please help me.
$domain ='www.singapore.com';
$id = mysql_insert_id();
$to = 'myemail#gmail.com';
$subject = "E-mail Verification";
$message = 'Click on the link to verify your account: http://'.$domain.'/rates/activation.php?id='.$id.' ';
$headers = "From: <Singapore> \r\n";
mail($to,$subject,$message,$headers, '-f enquiry#singapore.com.sg');
Do you need the -f envelope option? If memory serves, any address put in there needs to be already added as a trusted user in the sendmail configuration.
I found this on the PHP mail docs:
The user that the webserver runs as should be added as a trusted user
to the sendmail configuration to prevent a 'X-Warning' header from
being added to the message when the envelope sender (-f) is set using
this method. For sendmail users, this file is /etc/mail/trusted-users.
Are you simply trying to set the reply to and from addresses? If so, use the $header for that and don't bother with the additional parameters.
$headers = “From: enquiry#singapore.com.sg” . “\r\n” . “Reply-To: enquiry#singapore.com.sg”;
Something is wrong with your code. Change it to this
$message = 'Click on the link to verify your account: http://'.$domain.'/rates/activation.php?id='.$id;
It has extra quotes at the last.
Hope that helps.. :)

Categories