View Full Version : Changing the from field in emails sent from PHP?
probedb
01-11-2007, 07:07 AM
Hi all,
Anyone any idea how to stop emails coming from username@boxname.bluehost.com ?
I usually use the extra header (5th parameter in the mail function) and put '-femailaddress' and this works on every other hosting provider I've used except bluehost which causes the sending to fail. If I remove the 5th parameter, i.e. I have specified From: email address\n in the 4th parameter then it sends fine but always comes from the silly default email address.
Any thoughts as it's ****ed annoying?
Cheers :)
Paul.
areidmtm
01-11-2007, 09:07 AM
This works for me....Maybe it might help.
$to = "you@domain.com";
$subject = "TEST SUBJECT";
$message = "Hello! \n";
$message .= "More blah blah blah \n";
$message .= "blah blah blah blah blah blah blah blah blah \n";
$headers = "From: me@domain.com \r\n" .
"Reply-To: me@domain.com \r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
FYI: The from email address has to actually exists in cPanel.
Schelly
01-11-2007, 09:13 AM
You might also want to check in your php.ini file for this:
[mail function]
;SMTP = localhost ;
;sendmail_from = me@localhost.com ;
and uncomment out the sendmail_from line and configure it to your liking. Again, being sure that your from address actually exists, as areidmtm said above.
:)
probedb
01-11-2007, 11:07 AM
FYI: The from email address has to actually exists in cPanel.
That's what did it :) It would send from a non-existent address when just using From but if I add the -f it didn't work. Just added a forwarder and it works so cheers :D
seandelaney
01-12-2007, 01:22 PM
please post your code so i can have a look at it.
Sean
Professional Web Developer (http://www.seandelaney.co.uk/)
Free Mentor Written Articles (http://www.expertsrt.com/articles/index.shtml)
allieday
01-14-2007, 05:12 PM
Hi, I have the same problem.
Could you please post your code, and let me know which file you updated?
I did it in the php.ini file, but that doesn't seem to have fixed the problem.
I appreciate it, thanks!
emuen
01-15-2007, 01:10 AM
The problem was solved by adding the from email in the mail() function to the cPanel, so it exists in the bluehost repository. Otherwise, it will be changed to a default bluehost mail.
cjwysong
01-15-2007, 11:02 AM
I apologize for not knowing much... BUT, I can't find the php.ini file. I want to change it in order to solve the same issue. Where on earth is it?
cjwysong
01-15-2007, 12:03 PM
never mind... got it! :-)
probedb
01-17-2007, 03:45 AM
I use:
$result = mail("to@address.com", "subject here", "some message", "From: other@address.com\n", "-fother@address.com");
making sure other@address.com exists in cPanel either as a forwarder or a full POP3 account.
There is no need to touch php.ini!
allieday
01-18-2007, 11:29 AM
I use:
$result = mail("to@address.com", "subject here", "some message", "From: other@address.com\n", "-fother@address.com");
making sure other@address.com exists in cPanel either as a forwarder or a full POP3 account.
There is no need to touch php.ini!
So where then do you put that code? What page or file?
Darylt
03-02-2007, 12:35 PM
I have tried using another tutorial and some of the information in this thread to create a php send mail form.
I am now getting two email sent to me. 1 from and email address that I have set up and one from the bluehost.com email account.
This is my code
<?php
if(isset($_POST['submit'])) {
$to = "email-1@my-domain.com";
$subject = "Random Sheep Web Form Enquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$headers = "From: email-1@my-domain.com \r\n" .
"Reply-To: email-2@my-domain.com \r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Thank You
Your email has been sent to $to!";
mail($to, $subject, $body);
} else {
echo "Your email has failed, please try again.";
}
?>
Can anyone help?
areidmtm
03-02-2007, 01:33 PM
You have two mail() functions in there twice going to the same email address. What are you trying to do?
Darylt
03-02-2007, 01:54 PM
I am simply trying to create a script that will send me an email of the contents of a form.
I would like it to come from an email address relevant to my doman rather than a xxx@box402.bluehost.com
areidmtm
03-02-2007, 01:56 PM
Do you want the email to go to you and the person that filled it out?
Darylt
03-02-2007, 02:02 PM
Nope
Just to me
areidmtm
03-02-2007, 02:07 PM
ok then just use this:
<?php
if(isset($_POST['submit'])) {
$to = "email-1@my-domain.com";
$subject = "Random Sheep Web Form Enquiry";
$message = "From: " . $_POST['name'] . "\n";
$message .= "E-Mail: " . $_POST['email'] . "\n";
$message .= "Message:" . $_POST['message'];
$headers = "From: email-1@my-domain.com \r\n" .
"Reply-To: email-2@my-domain.com \r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
echo "Thank You, your email has been sent to " . $to . "!";
} else {
echo "Your email has failed, please try again.";
}
?>
Darylt
03-02-2007, 02:13 PM
I now get the following error message
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/angrytec/public_html/random-sheep/mailer.php on line 184
areidmtm
03-02-2007, 02:49 PM
Can you tell me what's on line 184
Darylt
03-02-2007, 10:24 PM
$subject = "Random Sheep Web Form Enquiry"; $message = "From: $_POST['name']\n"; $message .= "E-Mail: $_POST['email']\n"; $message .= "Message:\n$_POST['message']"; $headers = "From: daryl@random-sheep.com \r\n" .
areidmtm
03-02-2007, 11:08 PM
Just use the code exactly how I posted it. Or if you don't want to do that, then to use the $_POST variables in a string, then you have to do it like this:
$message = "From: " . $_POST['name'] . "\n";
msafi
04-06-2009, 01:30 PM
So, the "from" email address has to exist in the cPanel first. Otherwise, it will be replaced with the default email, which is username@boxXXX.bluehost.com.
How about the "name" and the "reply-to" fields? Can the PHP script specify those "on-the-fly" or do they also have to exist some where in the cPanel prior to being used?
I'm asking because I have a service on my Website that allows visitors to send emails to a small list of legitimate subscribers. I would've liked to even get my visitors email-addresses to appear in the "from" field, but with this limitation, I'm investigating workarounds. If I can specify a "name" and a "reply-to" address in PHP without having to go into cPanel, I think I may still be able to deliver my service via BlueHost.
So, is it possible?
msafi
04-07-2009, 04:16 PM
I was able to specify a name and a different reply-to address using headers in the mail() function of PHP.
The next thing that concerns me is attaching files to outgoing emails. I hope that it's doable through Bluehost.
felgall
04-07-2009, 07:00 PM
The next thing that concerns me is attaching files to outgoing emails. I hope that it's doable through Bluehost.
Yes it is.
aminulsumon
04-25-2009, 01:39 AM
You might also want to check in your php.ini file for this:
[mail function]
;SMTP = localhost ;
;sendmail_from = me@localhost.com ;
and uncomment out the sendmail_from line and configure it to your liking. Again, being sure that your from address actually exists, as areidmtm said above.
:)
i have shared hosting of bluehost. so i have changed sendmmail_from as
ini_set('sendmail_from' , 'webmaster@shopno-dinga.com');
here is my surprising problem, all recipient get my message at their inbox except yahoo(they get it as Spam)
ini_set('sendmail_from' , 'webmaster@shopno-dinga.com');
$to = 'aminul.test@yahoo.com';
$headers='MIME-Version: 1.0' . "\r\n";
$headers.='Content-type: text/html; charset=iso-8859-1' . "\r\n";
//$headers.='To: Faruk <farukpabna@yahoo.com>' . "\r\n";
$headers.="From:webmaster@shopno-dinga.com" . "\r\n";
//$headers.='Reply-To: webmaster@shopno-dinga.com' . "\r\n";
$message='very simple mail. only text no html currently.';
$subject='test mail from shonodinga';
mail($to, $subject, $message, $headers);
i have tried the following ways too. but result same (Spam for yahoo recipient)
mail($to, $subject, $message, "From: webmaster@shopno-dinga.com\n", "-fwebmaster@shopno-dinga.com");
felgall
04-25-2009, 02:24 PM
here is my surprising problem, all recipient get my message at their inbox except yahoo(they get it as Spam)
That's a problem with how Yahoo have their email configured so that it is misidentifying legitimate emails as spam. The only way to correct it is for the recipients to whitelist the sending email address or for them to convince Yahoo to fix the filter. There is nothing can be done on the sender's end.
That is one of the reasons why you see some sites that will not accept Yahoo email addresses when people are signing up for email lists.
msafi
04-25-2009, 02:31 PM
Actually, there is something the sender can do.
Yahoo! Mail, from what I heard, has a very good spam filter. One of the ways they identify whether an email is spam or not is by checking whether the email was sent from a server that has previously received spam complaints. And also from what I hear, since Bluehost is not very strict about how people send emails from their servers, many of them are blacklisted due to spam complaints. That's why emails sent from Bluehost tend to end up marked as spam with Yahoo! and even GMail, in my case.
To enhance deliverability of emails, the owner of the server could apply stricter rules to how the server is being used and try to get their servers removed from spam blacklists.
felgall
04-25-2009, 03:39 PM
since Bluehost is not very strict about how people send emails from their servers, many of them are blacklisted due to spam complaints.
BlueHost is extremely strict about spam which is one reason why they limit people to being able to send so few emails. Most accounts can only send a maximum of 50 emails per hour and no accounts can send more than a few hundred per hour and they have to convince BlueHost that they have a legitimate reason for wanting to send more than 50.
The problem is that sites like Yahoo are not correctly identifying the source of the spam. Where a BlueHost account has an email forwarder set up all the email sent to that address gets forwarded (including any spam). Where that destination address is on Yahoo the Yahoo filter misidentifies BlueHost as the origin of the spam whereas in fact the spam has actually come from elsewhere and just passed through BlueHost. Yahoo then blacklists BlueHost rather than the site the spam actually came from. The only way to fix this on BlueHost's end would be to stop everyone from being able to forward emails other than to other addresses on the same account. It would be much easier fixed on Yahoo's end if they were to examine the emails properly so as to correctly identify where they came from.
Yahoo isn't the only one that misidentifies the origins of spam. There are several other big free email services that make the same mistake and the big hosting companies are constantly having their servers misidentified by these email services as having sent out spam where in fact all of the spam actually originated elsewhere.
BlueHost wastes lots of time having to contact Yahoo and others that have incorrectly blacklisted BlueHost's servers due to their having incorrectly identified the source of spam emails.
Vegetta
05-21-2009, 06:59 AM
i capture the persons email and use it for the from email address
<?php
if (isset($_POST['submit'])){
$name=stripslashes($_POST['name']);
$street=stripslashes($_POST['street']);
$street2=stripslashes($_POST['street2']);
$phone=stripslashes($_POST['phone']);
$city=stripslashes($_POST['city']);
$zipcode=stripslashes($_POST['zipcode']);
$umail=stripslashes($_POST['umail']);
$state=stripslashes($_POST['state']);
$message=stripslashes($_POST['message']);
$ContactMethod=stripslashes($_POST['ContactMethod']);
$to = "myemail@mydomain.com";
$subject = "Contact From Website";
$submit = $_POST['submit'];
$msg = "Message from: $name\n\n
Address: $street $street_2 $city $state $zipcode $country\n\n
$umail\n\n
Phone: $phone\n\n
$message\n\n
";
$headers = "From: ". $name . " <" . $umail . ">\r\n".
$headers = "MIME-Version: 1.0;\n";
"Reply-To: $umail" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $msg, $headers);
echo '<h2>Thank you! ';
echo $name;
echo '</h2>';
echo '<p><strong>One of our representatives will contact you with the information you requested.</strong></p>';
}
?>
jacobchr
06-17-2009, 06:32 PM
<?php
$headers= 'Mime-Version:1.0'."\n".
'From: me@mysite.com'."\n"."\n";
$rc= mail('robert@oodledoodle.com', 'test subject', 'test message', $headers, '-r bounce@mysite.com');
?>
DonnaM200
01-15-2010, 05:19 PM
never mind... got it! :-)
Where is the php.ini file?
DonnaM200
01-15-2010, 05:33 PM
This works for me....Maybe it might help.
$to = "you@domain.com";
$subject = "TEST SUBJECT";
$message = "Hello! \n";
$message .= "More blah blah blah \n";
$message .= "blah blah blah blah blah blah blah blah blah \n";
$headers = "From: me@domain.com \r\n" .
"Reply-To: me@domain.com \r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
FYI: The from email address has to actually exists in cPanel.
Do you have an example script for phpformgenerator 'process.php' file which you could post so all who use phpformgenerator can copy and paste into their code.
DonnaM200
01-15-2010, 05:39 PM
Do you have an example script for phpformgenerator 'process.php' file which you could post so all who use phpformgenerator can copy and paste into their code.
=============================================
This is what phpformgenerator has in the 'process.php' file:
===========================================
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Suburb: ".$Suburb."
Phone: ".$Phone."
Mobile: ".$Mobile."
Email: ".$Email."
Please contact me about: ".$Pleasecontactmeabout."
";
$message = stripslashes($message);
mail("xxx@websitedomain.com","Enquiry from xxx Website",$message,"From phpFormGenerator");
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $Name."|".$Suburb."|".$Phone."|".$Mobile."|".$Email."|".$Pleasecontactmeabout."
";
fwrite($make,$to_put);
=============================
The email address exists in cPanel, infact two, one forwarding to the other both created in cPanel but still to no luck, still sends with username@boxname.bluehost.com
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.