This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP mail using Gmail
code :
<?
//change this to your email.
$to = "bhavesh412#gmail.com";
$from = "bhavesh412#gmail.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
* maaking.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#maaking.cXom[/email]";
// now lets send the email.
ini_set("SMTP","smtp.gmail.com");
ini_set("smtp_port","465");
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
I am getting below error:
Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\testMail.php on line 31
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\testMail.php on line 33
Gmail servers use TLS and login/password authentification, you can't use them with PHP's mail() function.
Try using a mail library like Swiftmailer. Here is an example that may work with Gmail: http://swiftmailer.org/wikidocs/v3/connections/smtp
You need to use SMTP authorization for gmail's SMTP server to work which you can't do with mail.
Take a look at PHPMailer they have a good example here.
sometimes an isp provides free smtp service for their clients to some degree. google yourisp & smtp.
Related
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:
Send email using the GMail SMTP server from a PHP page
(16 answers)
Closed 4 years ago.
<?php
if (isset($_POST["send"])) {
$to = $_POST["to"];
$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: your#email-address.com\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "SUCCESS";
} else {
echo "ERROR";
}
}
?>
This is my php code, I have a HTML form and $to, $subject, $message is the input fields of the form, the $_POST["send"] is the button through which I want to send emails after clicking that button
You can't send emails from your localhost server. Get a free PHP server and upload your files using ftp. Following are some free php server providers where you can test your project.
000webhost
Infinity Free
That's true, you can't send emails from localhost, unless you were using a VPS configured with DNS + public IP + email server;
If isn't your case, I would recommend sending emails through a SMTP server:
PHP Mail (php.ini configuration)
PHPMailer (library)
For the SMTP server you could use any provider that allows SMTP.
I am trying to send a mail with php. I watched in the internet to find a solution and I found diferent ways but not one helped me. When I come to the code where it should send the mail I got following error:
mail(): SMTP server response: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [AM4PR08CA0065.eurprd08.prod.outlook.com]"
mail call:
$mailAdr = "name#company.ch";
$subject = "subject";
$msg = "message!";
$header = 'FROM: My WebSite <name#company.ch>';
mail($mailAdr, $subject, $msg, $header);
I set the right smtp and port. Can anyone tell me what I am doing wrong?
I think you have to add your FROM header that is missing in your code.
<?php
$header = 'From: My Website <info#example.com>' . "\r\n";
mail($empfaenger, $betreff, $nachricht, $header);
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have part of my project when my clients will reseive mail after so many actions, when I testing my mail function, I have problem when the adresse is to "gmail" , I reseive the mail, but when the mail is no-gmail, the mail not reseived !!! :( this is my mail function:
function emailDemande($email, $name, $nameL){
$subject = 'Votre demande ';
$headers = "From: XXX <contact#emoovio.com>\r\n";
$headers .= "Bcc: abdelkhalek.oumaya#gmail.com, TEST#DOMAIN.com\r\n";
// $headers = 'From: XXX <'. $from. '>\r\n';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message='htmlmessage';
mail($email, $subject, $message, $headers);
};
Mail is very complex in his flow.
Your Mail Headers and Content
Does the sender mail address exist as mailbox or as forwarder? Sending mail with a non-existent mail address goes wrong.
What about the mail headers, subject and body? More info: https://sendgrid.com/blog/10-tips-to-keep-email-out-of-the-spam-folder/
The Sending Mail Server
Be sure the sending server (the smtp server) knows and allows the sender mail address to mail from.
Blacklist
Check if your smtp server is blacklisted. More info: http://mxtoolbox.com/blacklists.aspx
External Mail Service
I recommend to use external mail services, like Mailgun (http://mailgun.com). Mailgun provides an API for sending, receiving and tracking mail. A great advantage is that your own mail server (or global ip) cannot be blacklisted.
For testing your mail functionality, you can use Mailtrap (https://mailtrap.io).
I ran into a wee issue when using mail(). I wasn't able to send to addresses off the domain I was hosting the form. I understand this is for security reasons but it makes the creation of a 'send to friend' system a little tough.
Here's what I had working (albeit it only sent to my address):
<?php
$senderName = $_POST['name'];
$friendsEmail = $_POST['friendsEmail'];
if ($_POST['formName'] == 'refer') {
$to = $friendsEmail;
$subject = "$senderName has referred you";
$message = "Message goes here";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: Me <no-reply#test.com>' . "\r\n";
mail($to,$subject,$message,$headers);
}
header("Location: referConfirm.html");
?>
I've talked to my hosting company who setup a mail relay (yay!). Trouble is, I have no idea how to get what I working above through a mail relay. I have the following details:
IP: 000.000.000.000
Domain: domain.company.com
UN: username
PW: password
(Details are dummy.)
Can anyone give me a clue?
Thanks,
#rrfive
mail() uses the smtp/sendmail settings found in php.ini. If you need to send it via another smtp, or one with authentication (like in your example) mail is simply not enough.
There are good mailer libraries out there, just to name a few:
Swift Mailer
Zend_Mail
PHPMailer
They are all capable of sending emails via an authenticated smtp server.