PHP send mail through postfix - php

I have Postfix and SquirrelMail configured on my server. And user called noreply. So, I am logging to SquirrelMail and sending email to some address. Everything works fine, i am receiving email from noreply#mydomain.com. But when I try to send email from php using mail(),
mail ('test#2ether.net', 'Postfix Test', 'A test email');
server tries to send it from address www-data#mydomain.com. How do I configure it to send emails from noreply#mydomain.com?

I would use PEARMail it is designed to counter such issues, (PHP's "mail()" method is all but useless in today's email meta - too many bots used it ) however the actual answer is this:
$to = 'test#2ether.net';
$subject = 'Postfix Test';
$message = 'A test email';
$headers = 'From: noreply#mydomain.com' . "\r\n" .
'Reply-To: noreply#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

Related

Configuration send mail for send my from

I setup sendmail in linux server, I use my gmail.com accaunt as mail collector. I can send mail to different mail address in web, but I can not set my field from: in mail, the from: always set as my mail address... How to I can set my custom email address on field from: in mail?
p.s. sorry for my English.
You can do this by setting header as:
$headers = 'From: username#domain.com' . "\r\n" .
'Reply-To: username#domain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Then you can use:
mail($to, $subject, $body, $headers) to send mail where $to, $subject and $body are self explanatory variables.
For more info: visit http://php.net/manual/en/function.mail.php

mail() method using PHP, how do I set the sender?

I'm using iPage for my website, and I'm using a simple mail() method to send test mails from my page. On iPage, I have email capabilities via mark#domain.com. But when I send an email out, it comes from the iPage server and is sent from ipg.domain#boscustweb3506.eigbox.net, which is quite ugly looking!
Is there a way I can use the mail() method in php to send an email from my page that will use the shorter sender above? Thanks for any and all help!
you need to add a header named From. this code will send with the mail address webmaster#example.com:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Try this, You can add the From header to customise the sender address.
$from ='mark#domain.com';
$headers = 'From: ' . $from . "\r\n";
...
mail($to, $subject, $message, $headers);

noreply#example.com not working (rackspace)

I'm trying to use noreply to send out emails, but it doesn't work - it wont sent anything. I am using this test-file:
<?php
$to = 'myemailhere';
$subject = 'You received an email message!';
$message = 'This is a message in the email body form.';
$headers = 'From: noreply#example.com' . "\r\n" .
'Reply-To: noreply#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
What could be the problem? By the way, I am using rackspacke, if anyone should know about it.
Thanks in advance!
If you're running on a Rackspace cloud server, you will have to configure the server yourself to be able to send mail. The mail() function relies on the OS configuration to handle emailing. If you are on a Rackspace cloud site, you will likely need to contact Rackspace support for help.
Personally I dodge this bullet altogether by using PEAR's SMTP class. This is a full SMTP implementation in PHP and since it does not rely on any outside configuration or module, it is fully portable. It has saved me a LOT of trouble.
http://pear.php.net/package/Mail
http://pear.php.net/package/Net_SMTP
Note: The PEAR site is having some loading issues atm for me. Give it a minute and it should load.
what is exception? use try catch block. Else try this code
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

Sending mail from localhost using PHP

I am trying to send mail from localhost using PHP. I am using the following code to send the mail :-
<?php
$to = 'o****e#gmail.com';
$subject = 'hey You';
$message = 'Can you identify me :P';
$headers = 'From: at*****t#gmail.com' . "\r\n" .
'Reply-To: at*****t#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
At first, I tried to send the mail to myself(at*****t#gmail.com), it worked fine. However, after that, now if I am changing the $to, its still sending the mail to same ID(mine) with the previous contents(not the updated one).
Is my request getting cached somehow ? Why every mail is being repeatedly sent to me irrespective of change in both contents and $to ?
Go to your php.ini file and change SMTP = localhost to SMTP = aspmx.l.google.com and uncomment sendmail_from and put in your sending gmail address. and set smtp_port = 25
Restart localhost

PHP Mailing Code sending mail to spam/quarantine

The title explains itself. It is a website for in-house employees to buy and sell from each other. Its based solely around Microsoft Outlook emailing addresses. All the emails are supposed to be sent from the seller's email as they post items. Except when I enter <php phpinfo(); ?> on the action php page it tells me that the sendmail_from attribute thing is sending from a bogus email on the server. It seems to be the automatic email for the php script to send from. This may be why the emails are getting sent to spam, because the email is not valid. Also, I read online about having full and valid headers but most headers seem optional and i cant find anywhere that explains optimal headers. My mailing code:
//send approval email to the approver
$from = isset($_POST['from'])? $_POST['from']:1;
$message = isset($_POST['message'])? $_POST['message']:1;
$message = $message . '<a href="http://dev-corkboard/newapproval.php?id='
.$result[0][0].'"> Click here to approve website post.</a>';
// In case any of our lines are larger than 70 characters, we should use
// wordwrap()
$message = wordwrap($message, 70);
$to = 'clehane#eatonvance.com';
$replyto = isset($_POST['replyto'])? $_POST['replyto']:1;
$subject = isset($_POST['subject'])? $_POST['subject']:1;
$headers = "MIME-Version: 1.0" . "\r\n" . 'From: "'.$from.'"' . "\r\n" .
'Reply-To: "'.$replyto.'"' . "\r\n" .
'Content-Type:text/html;charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
//test message for email
}
header ("location: newindex.php"); `
Any ideas?
And bam! Solved it, needed to put email addresses as such:
$from = 'MyName <myemail#mycompany.com>';
And I also included these headers:
"X-Priority: 0\r\n".
"X-MSMail-Priority: Normal\r\n".
"X-Mailer: mycompany.com

Categories