mark103 Posted January 17, 2011 Share Posted January 17, 2011 Hi guys, I need your help. I am using the code below to send email via using with php, however, I can't be able to remove the mailed-by hostname which is something like: server01.domain.com. Here's the screenshot: Here's the code: if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@myemail.com"; $subject = $type; $message = $comments . ' ' . $rate; $header = "From: Your Name <tester@email.org>\l\n"; $header .= "Reply-To: no answer <myname@myemail.com>\l\n"; $header .= "Return-Path: tester@email.org\l\n"; $header .= "Envelope-from: tester@email.org\l\n"; $header .= "MIME-Version: 1.0\l\n"; $header .= "Content-Type: text/html\l\n"; mail($to, "test", "hello,how r u today? I'm a Noobie", $header); echo "Thank you for sent us your feedback"; When I use the code on above, the mailed-by hostname did not get removed. I want to remove it so I can send email to my clients for update email newsletters, registering form...etc Anyone who know how to remove the mailed-by hostname would be much appreciate. Thanks, Mark Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 17, 2011 Author Share Posted January 17, 2011 bump! please can someone help? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 Your answer is here: mail. Read it. Hint: note the optional fifth parameter. Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 18, 2011 Author Share Posted January 18, 2011 i have tried it, it doesn't work. any idea???? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 Post the code that you tried it with. Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 18, 2011 Author Share Posted January 18, 2011 Here it is: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'dbusername'); define('DB_PASSWORD', 'dbpassword'); define('DB_DATABASE', 'dbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $name = clean($_GET['name']); $email = clean($_GET['email']); $comments = clean($_GET['comments']); if($name == '') { $errmsg_arr[] = 'name or member ID missing'; $errflag = true; } else { } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['name'])) { $insert[] = 'name = \'' . clean($_GET['name']) .'\''; // echo "tested"; } if(isset($_GET['email'])) { $insert[] = 'email = \'' . clean($_GET['email']) . '\''; } if(isset($_GET['type'])) { $insert[] = 'type = \'' . clean($_GET['type']) . '\''; } if(isset($_GET['comments'])) { $insert[] = 'comments = \'' . clean($_GET['comments']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "example@example.com"; $subject = $type; $message = $comments . ; $header = "From: Your Name <tester@email.org>\l\n"; $header .= "Reply-To: no answer <myemail@gmail.com>\l\n"; $header .= "Return-Path: tester@email.org\l\n"; $header .= "Envelope-from: tester@email.org\l\n"; $header .= "MIME-Version: 1.0\l\n"; $header .= "Content-Type: text/html\l\n"; $add = "-f my-website.com"; mail($to, "test", "hello,how r u today?", $header); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $headers = "From: $email"; $to = "myemail@gmail.com"; $subject = $type; $rate = $_GET['rate']; $message = ".$comments." ; $mailHeader = "MIME-Version: 1.0\r\n"; $mailHeader .= "X-Sender: <{'google.com'}>\r\n"; $mailHeader .= "Content-Type: text/plain; charset=UTF-8\r\n"; $mailHeader .= "Content-Transfer-Encoding: quoted-printable\r\n"; mail($to, $subject, $message, $headers, $mailHeader); } echo "Thank you for sent us your feedback"; } } } ?> Hope you can help me to fix the problem i am getting. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 18, 2011 Share Posted January 18, 2011 First, this is incorrect <?php $add = "-f my-website.com"; ?> the "-f" takes a regular email address as it's argument. It should be <?php $add = "-f your.email@my-website.com"; ?> Second, you define $add, but never use it in your mail function. Try <?php mail($to, "test", "hello,how r u today?", $header,$add); ?> Ken Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks for your quick response Ken, I have adjusted with the variable in two lines. However I am getting this: Warning: mail() [function.mail]: SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE in /home/username/public_html/mysite.com/sendemail.php on line 79 The warning mail error are jumping on this line: mail($to, "test", "hello,how r u today?", $header,$add); What I can do about it?? Should I get into the safe mode to modify or to create mail function?? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 18, 2011 Share Posted January 18, 2011 You host has enabled safe mode and that parameter is not allowed in safe mode. Talk to your host to see if safe mode can be removed for your site. Or find a host that doesn't use safe mode. Ken Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks Ken, I will do that no problem. And thanks for your help anyway... Much appreciated. Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 18, 2011 Author Share Posted January 18, 2011 Ken, I can see that the mailed-by have been disabled. However, please could you help me with this? $name = $_GET['name']; $header = "From: "-f .$name."@myemail.com"; $to = "myemail@myemail.com"; $subject = $type; $message = $comments . ' ' . $rate; $header .= "MIME-Version: 1.0\l\n"; $add = "-f .$name. "@myemail.com"; mail($to, "test", "hello,how r u today?", $header, $add); I tried to send the email, but the php page have been blank. I am not sure that if my code is sound like a odd?? Quote Link to comment Share on other sites More sharing options...
Coolkat Posted January 18, 2011 Share Posted January 18, 2011 I think your quotes are off. $header = "From: -f". $name ."@myemail.com"; $add = "-f". $name ."@myemail.com"; seems in $add you are missing the " and it's "-f .$name. "#myemail.com" they don't all match up. Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks Coolkat, I have updated the code in my php. However I am getting the incorrect output email like this: From: 1.0l <-ftester@myemail.commime-version:> All I am trying to get rid of the "commime-version:" and extract the value from the $name method to included with my own email at the end like "myname@myname.com". Here's the update code: if(isset($name)) { $name = $_GET['name']; $header = "From: -f". $name ."@myownemail.com"; $to = "myname@myemail.com"; $subject = $type; $message = $comments . ' ' . $rate; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myownemail.com"; mail($to, "test", "hello,how r u today?", $header, $add); echo "Thank you for sent us your feedback"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 18, 2011 Share Posted January 18, 2011 The "From:" header should not contain the "-f", change <?php $header = "From: -f". $name ."@myownemail.com"; ?> to (you also need the EOL character at the end of that header) <?php $header = "From: {$name}@myownemail.com\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 19, 2011 Author Share Posted January 19, 2011 Thanks for the help ken, last thing I need before i will mark this thread as resolve. How I can check the methods between $name and $email that if I enter the value? if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myownemail.com"; $to = "myname@myownemail.com"; $subject = $type; $message = $comments . ' ' . $rate; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myownemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { } if(isset($email)) { $email = $_GET['email']; $headers = "From: ".$email."; $to = "myname@myemail.com"; $subject = $type; $message = $comments . ' ' . $rate; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); } echo "Thank you for sent us your email"; } If I enter the value into 'name', it will work but if I enter the value into 'email', I get the blank page. Do you have any idea why I get it?? Quote Link to comment Share on other sites More sharing options...
mark103 Posted January 19, 2011 Author Share Posted January 19, 2011 bump Quote Link to comment Share on other sites More sharing options...
Coolkat Posted January 19, 2011 Share Posted January 19, 2011 A few comments: 1.) earlier in your code you cleaned your input with a clean() function, but then right before actually using it, you reset the clean value to the unclean value with $name = $_GET['name'].. since $name already is the clean value of $_GET['name'] 2.) you have $headers (notice the S) and then $header, it looks to me like you want to append them together but they have different names so that doesn't work. also if that is the case you need a new line after the from field. 3.) In the email section, you have $headers = "From: ".$email."; so the last ." is not there and messing with your code. As per your question are you asking how to check to make sure the information was entered into a form before sending the message? I think this would best be done in javascript on that page but you seemed to have it right there with the isset($email) and such. Quote Link to comment Share on other sites More sharing options...
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.