fazlionline Posted September 26, 2009 Report Posted September 26, 2009 (edited) Hi all I have this script to send form data to my email Everything goes perfect, but there is no ?Message? text in my inbox. I receive all information but do not receive which are written in Message text area. My code is: <?php $to = "123@yahoo.com"; $subject = $_REQUEST['subj'] ; $org = $_REQUEST['org'] ; $tele = $_REQUEST['tele'] ; $city = $_REQUEST['city'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $details = "Subject: $subject\n Organization: $org\n Telephone: $tele\n City: $city\n From: $email \n "; $headers = "From: $email"; $sent = mail($to, $subject, $details, $headers, $message) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> 123@yahoo.com is written just for security purpose here need help Edited September 26, 2009 by fazlionline Quote
falkencreative Posted September 26, 2009 Report Posted September 26, 2009 $message = $_REQUEST['message'] ; $details = "Subject: $subject\n Organization: $org\n Telephone: $tele\n City: $city\n From: $email \n "; Well, if you look at your code, you aren't actually including the message in the $details variable. You need to use this instead: $message = $_REQUEST['message'] ; $details = "Subject: $subject\n Organization: $org\n Telephone: $tele\n City: $city\n From: $email \n Message: $message "; Also, minor detail, but due to security issues with $_REQUEST it is better practice to use $_POST[] rather than $_REQUEST[]. From php.net: "Note: The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted. The presence and order of variables listed in this array is defined according to the PHP variables_order configuration directive. " http://us2.php.net/manual/en/reserved.variables.request.php Quote
fazlionline Posted September 26, 2009 Author Report Posted September 26, 2009 yes, but i have inlcuded $mssage at this line $sent = mail($to, $subject, $details, $headers, $message) ; why, the last variable, $message, is not comming in my inbox? i know you you said, and that is possible, but i am confused with the last variable in mail(). Quote
falkencreative Posted September 26, 2009 Report Posted September 26, 2009 $sent = mail($to, $subject, $details, $headers, $message) ; Oops, didn't see that. If you look at the PHP manual's entry on mail() (http://us2.php.net/manual/en/function.mail.php) you'll notice that this is the standard from: bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) You can't simply add on variables and expect PHP to understand what to do with them -- you have to follow the form that appears in the manual. Anything that you want to have appear within the message needs to included within that 3rd variable (in your case, you called it "details". In order to include $message within the email, you need to do what I specified in my first post. Quote
fazlionline Posted September 30, 2009 Author Report Posted September 30, 2009 (edited) Thanks falkencreative I have made that form and it works well. Thanks for your help. I upload this form to website, filled it and emails was sent to me with exact information. Thanks a lot The final code was: <?php $to = "123@yahoo.com"; $subject = $_REQUEST['subj'] ; $name = $_REQUEST['name'] ; $org = $_REQUEST['org'] ; $tele = $_REQUEST['tele'] ; $city = $_REQUEST['city'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $url = "KGC - Contact Form"; $details = "\n URL - Form: $url\n Subject: $subject\n Name: $name\n Organization: $org\n Telephone: $tele\n City: $city\n From: $email \n Message: $message \n "; $headers = "From: $email"; $sent = mail($to, $subject, $details, $headers, $message) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> thanks Edited September 30, 2009 by fazlionline Quote
fazlionline Posted September 30, 2009 Author Report Posted September 30, 2009 Hi I have copied the same code to another website. But I removed two fields form there, the organization and telephone fields. I have uploaded to other site, and when I fill the form and click on submit button, I recive this error: Warning: mail(): SMTP server response: 553 5.3.0 ... DISCARD Spam Relay in d:\Customers\user1092190\www\test\contactus.php on line 17 We encountered an error sending your mail I think the code is correct, but this may be with website strong security or something else. My code is here: <?php $to = "123@yahoo.com"; $url = "EG - Contact Form"; $subject = $_REQUEST['subj'] ; $city = $_REQUEST['city'] ; $email = $_REQUEST['email'] ; $message = "Register me for Monthly Newwsletter" ; $details = "URL - Form: $url\n Subject: $subject\n City: $city\n From: $email \n Message: $message \n "; $headers = "From: $email"; $sent = mail($to, $subject, $details, $headers, $message) ; if($sent) {print "You are successfully added to our monthly newsletter"; } else {print "We encountered an error sending your mail"; } ?> Quote
jlhaslip Posted September 30, 2009 Report Posted September 30, 2009 (edited) The "From" header needs an address that the Mail Server does not consider to be Spam. I should be an email address from the Domain the Server recognizes. Although the message may be sent from your site, if the from header says it is coming from me@jlhaslip.com and the domain name jlhaslip.com is not hosted there, the Mail server will consider it a Spam email. Try the form using a valid email address. The Email address the user supplies should be part of the message, not a Mail Header. *edit* The From Header needs to be the Domain's Email address. Edited September 30, 2009 by jlhaslip Quote
fazlionline Posted October 1, 2009 Author Report Posted October 1, 2009 The "From" header needs an address that the Mail Server does not consider to be Spam.I should be an email address from the Domain the Server recognizes. Although the message may be sent from your site, if the from header says it is coming from me@jlhaslip.com and the domain name jlhaslip.com is not hosted there, the Mail server will consider it a Spam email. how can i fix this problem? is script in the following code is wrong? $email = $_REQUEST['email'] ; $headers = "From: $email"; or i sould change the code here Quote
falkencreative Posted October 1, 2009 Report Posted October 1, 2009 If I understand it correctly, @jlhaslip is saying that this line: $headers = "From: $email"; is incorrect. Since this message is coming from a website, not directly from that person's email address, your server is giving you an error. Include $email within the $message variable instead, and in the $header variable, set the "from" address to be an email address that has the same domain as the website the form is in. Quote
fazlionline Posted October 1, 2009 Author Report Posted October 1, 2009 (edited) i made an email on my domain, like real_email@mydomain.com then sit the follwoing code: <?php $to = "123@yahoo.com"; $subject = $_REQUEST['subj'] ; $name = $_REQUEST['name'] ; $city = $_REQUEST['city'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $url = "EG - Contact Form"; $details = "\n URL - Form: $url\n Subject: $subject\n Name: $name\n City: $city\n From: $email \n Message: $message \n "; $headers = "real_email@mydomain.com"; $sent = mail($to, $subject, $details, $headers, $message) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> but i still get error Edited October 1, 2009 by fazlionline Quote
fazlionline Posted October 1, 2009 Author Report Posted October 1, 2009 (edited) *Edited* Edited October 1, 2009 by fazlionline Quote
jlhaslip Posted October 1, 2009 Report Posted October 1, 2009 http://www.php.net/manual/en/function.mail.php change this line of your code: $headers = "real_email@mydomain.com"; $sent = mail($to, $subject, $details, $headers, $message) ; to: $headers = "From: real_email@mydomain.com"; $sent = mail($to, $subject, $details, $headers) ; and see if it works. Quote
fazlionline Posted October 3, 2009 Author Report Posted October 3, 2009 (edited) Jlhaslip i made thsese changes and got this error agian: Warning: mail(): SMTP server response: 553 5.3.0 ... DISCARD Spam Relay in d:\Customers\user1092190\www\test\contactus.php on line 19 We encountered an error sending your mail . oops Edited October 3, 2009 by fazlionline Quote
fazlionline Posted October 3, 2009 Author Report Posted October 3, 2009 i have solved this problem and got a new code while googling ... $email = $_REQUEST['email'] ; ini_set("sendmail_from", $email); $headers = $email; $sent = mail($to, $subject, $details, $headers, $message) ; ... this code solve the problem and i can resive the email in my yahoo inbox. but one thing i was so confused with: the same code i posted at first on this topic, i used it in other site. it was working there directly. but in second site, this have pasted same code and i solve it with this new lines in my code. i do not know y Quote
falkencreative Posted October 3, 2009 Report Posted October 3, 2009 the same code i posted at first on this topic, i used it in other site. it was working there directly. but in second site, this have pasted same code and i solve it with this new lines in my code. i do not know y That will just depend on the security settings of the web host. Some are more strict than others. Quote
fazlionline Posted October 4, 2009 Author Report Posted October 4, 2009 yes, you are right but some one told me that you can go to your control panel and make changes there. then you will past the simplist mail () script and it will work. will any one tell me where can i make changes? Quote
falkencreative Posted October 4, 2009 Report Posted October 4, 2009 but some one told me that you can go to your control panel and make changes there.then you will past the simplist mail () script and it will work. will any one tell me where can i make changes? I don't believe there is one consistent way to do things, since different hosts have different settings, and may offer different control panels. In most cases, the web host gives no direct access to the PHPini file, which is why you may have to do the "ini_set("sendmail_from", $email);" workaround. Quote
fazlionline Posted October 4, 2009 Author Report Posted October 4, 2009 OK Thanks to everyone You people helped a lot to solve my problem Regards Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.