I'm trying to send mails from my server by google app.
I am using this php code :-
$to = "username#gmail.com";
$header = "From: username#netvigator.com";
$subject = "testing mail";
$message = "no reply pls";
ini_set("SMTP","smtp.gmail.com");
ini_set("SMTP_PORT", 23);
ini_set("sendmail_from","username#fullpiracy.com");
ini_set("auth_username","username#fullpiracy.com");
ini_set("auth_password","password");
mail($to, $subject, $message, $header);
Thanks in advance !
This was done with send mail open source library.
http://www.sendmail.com/sm/open_source/
I believe Gmail uses SSL (or TLS), so you should adjust your settings accordingly.
The port is usually 465 for ssl connection and 587 for TLS, and address are ssl://smtp.gmail.com and tls://smtp.gmail.com respectively.
Here is a link to a useful SO question that may be helpful.
Related
I have the following config file for msmtp
account default
host SES_HOST
port 587
timeout 5
auth on
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
syslog on
set_from_header on
allow_from_override off
user SES_USERNAME
password SES_PASSWORD
from SES_VERIFIED_EMAIL
php.ini
sendmail_path = /usr/local/bin/msmtp -ti
I want to make sure all emails sent via php use the SES_VERIFIED_EMAIL in the from header so SES does NOT reject the email. I thought setting the from allow_from_override on and allow_from_override off would mean that email send from php with a from header that is NOT SES_VERIFIED_EMAIL would be replaced by SES_VERIFIED_EMAIL so the message will be sent
But I can only send emails via php where the from header is already put in as SES_VERIFIED_EMAIL but I need it to work in all cases. It doesn't appear the from header is being replaced
I want msmtp to override the From header to SES_VERIFIED_EMAIL so it does get sent. I thought the settings above would do it.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: NOTSESVERIFYED#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Change:
set_from_header on
To:
set_from_header off
Try:
from SES_VERIFIED_EMAIL
rewrite_domain SES_VERIFIED_EMAIL
The rewrite_domain option is used to rewrite the domain part of the From header. This is useful if you want to send mail from a domain that is not your own. The domain part of the From header is rewritten to the value of the rewrite_domain option. The local part of the From header is not changed.
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);
?>
I've written a mail script as;
<?php
$to = 'something#domain.com';
$subject = 'This is subject!';
$body = 'Welcome to our website!';
$headers = 'From: myemail#mydomain.com' . "\r\n" .
'Reply-To: myemail#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent = mail($to, $subject, $body, $headers);
if($sent) {
echo "Your mail has been sent to ". $to .".";
} else {
echo "You mail was not sent.";
}
?>
And I could see the echo "Your mail has been sent to someone#somedomain.com" for mail being sent in all of the cases regardless of what email is but the emails are being delivered only to something#gmail.com but never on something#hotmail.com or something#yahoo.com or something#domain.com (hosted on google apps).
I wonder if there is any server configuration missing or the server has been blocked for hotmail/yahoomail or any error there is? Is there any thing you guys can help/suggest me for this?
I've configured my cPanel mail to be recieved at google apps, but I think that doesn't matter as I am trying to send mail, not recieve with this code here.
And yes, I've tried checking in the SPAM/JUNK folders and also waited lots of minutes to see them not being delivered. ;(
Hello Please check sender email sendbox also ,there may be mail in sendbox with some error message. or it may be that on your host the reverse DNS wasn't setup correctly..thanks.
You must authenticate your email with your password before sending, so it won't get blocked in the server. if you use mail class like phpmailer to send mails, following example will help you.
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
Php mailer -- Download phpmailer in this website.
SMTP demo -- Nice tutorial how to use php mailer to send authenticated mails.
All,
I have the following code:
$to = $friend_email[$x];
$subject = "Subject";
$message = "This is a message";
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
When the email sends (I'm using Godaddy's hosting service) it says From correctly but then in gmail it says via pxnlhgxxx.prod.xhx3.secureserver.net. Is there anyway to hide the via part or make it say something like website.com? Thanks for the help.
As per the mail() docs, you use the optional 5th parameter for the function and pass in the name of the server you'd like to masquerade as:
mail($to, $subject, $message, $headers, "-f sender#website.com");
If your hosting off godaddy then something like that will happen. You can use your own SMTP server, or use Google free SMTP Server (logging in with your gmail account). Host Gator does the same thing.
You can prevent Google from showing the 'via' notice by DKIM signing your outgoing mail to prove that you genuinely control the domain you're sending e-mail on behalf of.
Its all up to the configuration of the smtp server.
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.