This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
Hi I am trying to create my contact form and link it up with my Gmail account which I have. I have been trying to use the normal simple way by creating a HTML form and PHP file so that I can use the mail() function to send the email but this does not seem to work at all.
I want to create a contact form which links to my Gmail account and works when I host it on my server which is godaddy. This is driving me insane for the past 4 hours!!
Gmail is not the only mail service that will ignore sendmail emails.
If you're using 3rd-party hosting, you should find out the host name (e.g. "myhost.com") and use that in your From: header. Then use the correct email address in the "Reply-To" header instead.
Just for example:
$mailheader .= "Reply-To: Some One <someone#mydomain.com>\r\n";
$mailheader .= "Return-Path: Some One <someone#mydomain.com>\r\n";
$mailheader .= "From: Some One <mydomain#myhost.com>\r\n";
$mailheader .= "Organization: My Organization\r\n";
$mailheader .= "Content-Type: text/plain\r\n";
To increase deliver ability, you should use SMTP to send a mail via an actual email account.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
How do I prevent mails sent through PHP mail() from going to spam? [duplicate]
(6 answers)
Closed 3 years ago.
So a company I am helping out has outlook for their mail. Unfortunately, outlook seems to be very inflexible on how I can set up emails. I have added multiple domains to the outlook admin center for our multiple different sites. However, it will not let me create anything useful with the new domains.
For instance, we have "information#ourMainDomain.com" set up as an account.
I tried to create an alias on this account for "information#aSecondaryDomain.com" but then outlook gives me an error saying "information#ourMainDomain.com" already exists. Evidently you cannot use the same username even with different domains.
Fine. So i tried to create a shared mailbox - same issue. information#aSecondaryDomain.com is not allowed, because information#ourMainDomain.com exists... getting frustrating now!
So, after experimenting, trying everything, and spending 2 hours on the phone with outlook support that got me no where, i opted for my own route:
I created a Distribution Group called information#aSecondaryDomain.com, told this that senders outside the organization can send to it, added all the people that need to be involved, and gave them all send access.
This allows us to send emails as info#aSecondaryDomain.com
It allows us to recieve them here as well.
Also, i can send from outside the organization, ie from my gmail i can send to this account and it comes through, Great!
The problem is when i use php for a contact form, it WILL NOT send to the distribution group. It is not going to junk that i can see, and mail trace doesnt show it ever coming in at all. If i change the send to address of mail function to one of our main emails with the organization it comes through. If i change it to send to my gmail it comes through. As soon as i set it to the address of the distribution group, it will not come through. I see no errors on the php, it thinks it sent... but it never does.
Does anyone have an ideas? Or has anyone done this before?
The code in question is very simple...
<?
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$subject = $_REQUEST["subject"];
$msg = $_REQUEST["msg"];
$to = "information#aSecondaryDomain.org";
if (isset($email) && isset($name) && isset($msg)) {
$email_subject = "$name sent you a message";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$name." <".$to.">\r\n"."Reply-To: ".$to."\r\n" ;
$msg = "From: $name<br/> Email: $email <br/> Subject: $subject <br/> Message: $msg";
$mail = mail($to, $email_subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
EDIT: I have no tried PHPMailer... same reuslt - it will send to my regular work address, and my personal, but not to the distribution group.
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Send email using the GMail SMTP server from a PHP page
(16 answers)
Closed 4 years ago.
I currently have a php script to send emails from Ubuntu server with sendmail.
$to = $sendTo;
$subject = $subjectPrefix . $subject;
$txt = $message;
$headers = array(
"From: ". $email,
"Reply-To: ".$email,
"Content-type:text/html;charset=UTF-8",
"MIME-Version: 1.0",
"X-Mailer: PHP/" . PHP_VERSION
);
$headers = implode("\r\n", $headers);
if(mail($to,$subject,$txt,$headers)){
echo "sent";
}
else {
echo "failed";
}
The emails send fine but always go into spam and have the server address attached to the email, for exmaple: "input#email.com"#ip-###-##-##-###.eu-west-2.compute.internal
How would i go about setting this to only show the input email and not go into spam?
It's because the mailserver you're using to send your email does not belong to the domain of the sender, and is therefore not a 'trusted' source.
You can use SMTP server of your email's domain. For example, if you want to use email from Google's Gmail Service as From address , you have to use the Gmail SMTP server.
So, you can add SMTP email rely for SendMail. How to do it you may read here
Also, you can install SMTP client msmtp and configure PHP for using it. Instructions here
At last, if you don`t want to configure your server, you can use PHPMailer library.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm using a basic script on a 1&1 hosted server:
$recipient = "email#domain.com";
$sender_name = $_POST['name'];
$sender_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html; charset=UTF-8"."\r\n";
$headers .= "From: {$sender_name} <{$sender_email}>"."\r\n";
$headers .= "Reply-to: {$sender_name} <{$sender_email}>"."\r\n";
mail($recipient, $subject, $message, $headers);
..but for some reason am not receiving any emails, nor any errors as per PHP mail() function not sending email instructs.
I thought this may be a server issue but 1&1 states that it is fully supported. I've also sent emails from this server/hosting before using just a recipient, subject and body and so I'm rather unsure as to why it is not working now!
UPDATE
Sending without headers, i.e.:
mail($recipient, $subject, $message);
..does work, so it would appear to be an issue with using the headers?
There may be many reasons, for example you should study what SPF is.
The $sender_email can't be any address, for example you can't put a gmail address and send emails claiming to be that sender, without any authentication, you aren't allowed to send email on behalf on that address, because I could for example send emails putting your address in the from, pretenting to be you when I'm not (I tried to use simple words)
You should use in the From something ending in #yourdomain.com, and set up SPF to allow your server's IP to send emails for that domain. OR otherwise send emails through SMTP (with PHPmailer, for example, it's very easy)
Errors in header does affect the mail delivery. if you send email with wrong headers, for example, let's say the email of the user is user#email.com and his name is "user user", and you send the email to user#email.com it might cause the email to go in spam or not accepted at all if it doesn't match on server.
Gmail, for one, has a name associated with every email id. if you put a wrong name with the email, there's a chance the email might not show up in inbox or sometimes even spams.
"But in the link I attached the example given uses a 'from' header set by a form input?"
if you want your users to be able to send email to you, best idea would be to use your own email address as the sender email. E.g. if your website is at website.com, configure an email like "contact#website.com" and configure your script to use this as From header, you can send it to your own email at the same domain(website.com) or any other email which you authorize. You can add the users's actual details in the mail. that'll ensure the successful delivery of the email always.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have made a password recovery option in my website using php mail function. It works with gmail and yahoo but when the email is hotmail it does not works, I tried many time. When I tried with my companies email (outlook) nothing happens. It only works with gmail and yahoo. What can be wrong with it. the code I am using is her below:
$email= "customer_email_address";
$head = "From: \"Pizza Hut Pakistan\" <no-reply#pizzahut.com.pk>\n";
$head .= "X-Mailer: RegFormPHP\n";
$head .= "Priority: urgent\n";
$head .= "Importance: High\n";
$head .= "Content-Language: en-us\n";
$head .= "Reply-To: <no-reply#pizzahut.com.pk>\n";
$head .= "Organization: \"Pizza Hut Pakistan\"\n";
$head .= "Content-Type: text/html\r\n";
$msg = 'Click the link below to proceed <br><br>';
$msg .= 'http://'.$_SERVER['HTTP_HOST'].'/root_folder/forgotlink.php?id='.$unique_code_of_user;
mail($email, "website account password recovery", $msg, $head);
every thing is cool with gmail and yahoo. but..... nothing works with others....
Thanks
Hotmail is probably rejecting your emails thinking it's spam.
Hotmail is known to be a PITA when it comes to emails... You can check if you have correct DKIM and SPF parameters, see if your server isn't blacklisted, or better yet, use a mailing provider like MailChimp, SendGrid or similar to be sure your emails are sended in best conditions.
You can try class.phpmailer.php. It works for Yahoo, Hotmail, GMail,
This question already has answers here:
Gmail and Hotmail marked as spam
(5 answers)
Closed 8 years ago.
My emails that are send by mail() are getting directly into the spam box, tested with GMAIL and HOTMAIL.
So:
I have dedicated server
My server ip is not listed on any blacklists
This is my code:
function send_email($recipient, $sender, $subject, $email_body){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$sender;
mail($recipient,$subject,$email_body,$headers);
}
$from = 'info#domain.com';
$subject = 'subject';
$email_body = '<h1 style="text-align:center;">Title</h1><p>Message</p>';
send_email($userbday['email'], $from, $subject, $email_body);
Any thoughts?
Try to setup an SPF record for your domain.
Also
Email is serious business.
Try transactional email service providers
It may be that your email looks exactly as spam. It sometimes happens...
All my applications sends email - depending on how the client prepare the email templates - some are treated as spam almost instantly, some not.
Setting SPF Record can help, but also check (and use) some blacklist emails for your own good - like people who dont want to receive your emila should never be bothered again as they can trigger your server to be in the black lists (for example spamcop).