Send mail through mail relay with PHP - php

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.

Related

Subject issue with mail function - PHP

I'm trying to send e-mail using PHP. I took a piece of code that I have been using earlier, but it doesn't work anymore. I figure out the problem was coming from the subject.
When my subject is "test", the mail is sent, but when my subject is anything else with for example capital letters, like "Test", it doesn't work. I'm pretty sure this is a quick fix, but I can't find the answer.
Here is my code.
In index.php
$subject= 'test';
$message = implode("\n" , $_SESSION['data']);
mail_html($subject, $message, $email);
In functions.php
function mail_html ( string $subject, string $message, string $receiver) {
$headers = 'From: Template <me#me.com>' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';
mail($receiver, $subject, $message, $headers);
}
Thank you everyone for helping me. I feel stupid getting blocked by things like that.
Sending E-Mails is a very difficult process. So you can't send E-Mails so easy from your Computer or Server if you don't have alle the common SPAM prevention mechanisms enabled.
So when you don't a Reverse-DNS entry and you send an Email with "Test" you should not wonder if the emails can't send to the other site. So Take a look at the SPF-System, Reverse-DNS and generic names for servers (not working for some providers). Then you can send some E-Mails.
To find some problems check your mail log /var/log/mail.log.
When you try to prevent that problems use an SMTP account from your provider and send that E-Mails over SMTP.

php mail function not sending email to gmail account only

i am facing a weird problem in my php script. i have made a function to send email and calling the function in my php page. the function works fine when i send mail to yahoo or any other domain but fails when it comes to send mail to the gmail account.below is my code
function send_mail($p_to , $p_sub, $p_body)
{
$from = 'xxx#mydomain.com';
$to = $p_to;
$email_subject = $p_sub;
$email_body = $p_body;
$xheaders = "";
$xheaders .= "From: <$from>\n";
$xheaders .= "X-Sender: <$from>\n";
$xheaders .= "X-Mailer: PHP\n"; // mailer
$xheaders .= "X-Priority: 1\n"; //1 Urgent Message, 3 Normal
$xheaders .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
mail($to,$email_subject,$email_body,$xheaders);
}
//
when i send mail directly to a gmail account for example if a create a new page with the above code by taking hardcoded values for all the fields($p_to,$p_subject,$p_body) and sends mail then it works .
it was working fine earlier and sending mails to gmail account but, somehow stopped working for gmail.i checked the spam bucket also but found nothing.
any idea frnds ???
Google marks all not verified domains as blacklisted, so your email will be directly moved to the spam box of the gmail user. I think the only thing you can do is to send a mail to the customer service of google and ask if they can verify your domain as safe, but only if you find it really important that gmail users get it in their inbox and not in their spam box.
problem was sorted out. server side modification needed.
Thanks for your replies guys :)

PHP mail may be filtered out by spam?

I am creating a small company, and would like to send out emails to my clients once they have signed up for my service to activate their accounts. I am currently using PHP's mail() function, however I am worried that my emails are being filtered out by spam filters. Is there a better way to go about this?
$email = 'XZY Client Email address # somedomain.com';
$emailSubject = "Welcome to XYZ Service!";
$to = $email;
$subject .= "".$emailSubject."";
$headers .= "From: no-reply#XYZService.com\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "Welcome to XYZ Service! \n Activate your account by clicking the following link: link...";
mail($to, $subject, $message, $headers);
Is there a way to authenticate these emails so that my clients know that they are from my actual service? Thank you in advance!
You can try to get your mail server white listed by some of the major postmasters (AOL, Gmail, Hotmail, etc.).
I am not sure if this is what you want, but you can setup a mail server to handle all your emails.
Try using that mail server for sending emails and see if they are still filtered or not.
BTW, setting up a mail server on *nix systems is free and worth giving a try.
I have a simple arcade site that people from my highschool use and for quite a while I've been using the method that you showed. I didn't look at my code to verify that they're identical, but they look fairly close and mine works with gmail and all other big name services I've ran into!
Just remember that some hosting companies limit the amount of PHP mail that can be sent per minute. Mine only allows 9 per minute, I know I've gotten suspended a few times on accident while running test mail sends, haha.

why the mail function not working

Why the mail function not sending mail to me ,Could any one please help me ?
Here i have wrote script to mail sending.
Is there any other settings to send mail.
But the mail function printing always "Success" , but the mail not received to me.
$Msg = "Your Suggestion is saved successfully. Please wait for admin approval";
$subject="New Suggestion Posted - Waiting for approval";
//$email_id = 'bajrang.lal#sunarctechnologies.com';
$email_id = 'bajrang.lal#sunarctechnologies.com';
$mail_msg="Hello Admin,<br><br>New Suggestion Posted. Waiting for approval.<br><br>
Suggestion : ".$frmdata['description']."<br><br> Click here for <a href='http://www.tatanykshipping.com/index.php'>login</a><br><br> Thanks,<br>The TATA NYK Team";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Tata NYK <".$_SESSION['EMAIL_ID'].">\r\n";
$headers .= "Organization: Tata NYK\r\n";
echo '<br>sending mail to = ',$email_id;
if(mail($email_id,$subject,$mail_msg,$headers))
echo '<br>Successs';
else
echo '<br>Fail';
Thanks a lot in advance.
If your PHP application is running on Linux and expecting to send mail from that system, you need a transport. I use sendmail, but there are other open source transports you can use. You may also have to install an email client, but I do not know how PHP interacts with sending mail. My applications act like an email client, and need the email client installed.
You also need to make sure that the email recipient will accept unsolicited port 25 traffic. Because of spam-ware, our firewall won't accept unsolicited port 25 traffic, so I have doctored up sendmail to log into our email server as a legitimate email account.

My php script that written for sending mail is not working

I have created a form and written a php script to send a mail after clicking the submit button, and display a thank you message after sending the mail. The "Thank you" message is put into another HTML page.
I put those to WWW folder in WAMP server and try it. The "Thank you" page is displayed but the mail is not sent to my mail account.
Why did it not send my mail? Is it necessary to host the web site to do this?
This is the code that I'm using:
<?php
$email_from = 'aa#gmail.com';
$email_subject = "Arrange new Safari service";
$email_body = "You have received a new message from $name.\n"
$to = "aa#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thanking.html');
?>
Please read here Sending email from localhost
And here http://forums.devshed.com/mail-server-help-111/how-to-set-up-php-ini-to-send-mail-from-106329.html
If you use the php mail() function, you need an smtp server. Right, that might run on you hosting.
You might also use a librairy like http://swiftmailer.org/ to get it easier (you will be able to use remote smtp servers without pain)
There appear to be some syntax errors in the code you have supplied:
$email_from = 'aa#gmail.com';
$email_subject = "Arrange new Safari service";
$email_body = "You have received a new message from $name.\n";
$to = "aa#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thanking.html');
I have attempted to fix the syntax above.
You need to configure PHP to use a working SMTP service in order to send SMTP email.
Basically, it appears that the SMTP configuration for your PHP instance is using default values, which point to localhost. But your local computer doesn't seem to be running an SMTP service. So you'll need to point is to a server that is running one, and one which your application is permitted to use.
You have to configure your php.ini with a valid smtp server and email address.
Check this article http://www.sitepoint.com/advanced-email-php/

Categories