mark103 Posted January 26, 2011 Share Posted January 26, 2011 Hi guys, I have a problem with the $header variable. I am trying to extract the value from the $name method and included with the $email method. <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbname'); $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']); $type = clean($_GET['type']); $comments = clean($_GET['comments']); if($name == ''){ $errmsg_arr[] = 'name are missing.'; $errflag = true; } elseif($email == ''){ $errmsg_arr[] = 'email are missing.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['name'])) { $insert[] = 'name = \'' . clean($_GET['name']) .'\''; } 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($email)){ $name = $_GET['name']; $email = $_GET['email']; $header = 'From: $name <-f $email>' . "\r\n"; $to = "[email protected]"; $subject = $type; $message = "$comments"; $header .= "MIME-Version: 1.0\l\n"; mail($to, $subject, $message, $header); echo "Thank you for sent us your email"; } } } ?> Something got to do with this line: $header = 'From: $name <-f $email>' . "\r\n"; My problem is I can see in my email that the sender name has been included with (unknown sender) while the email address are display as empty address. I am really not sure why I have got the blank sender name and with the blank sender address. Do you know what the main problem is and what I need to change it with? Any advice would be much appreciate. Thanks, Mark Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/ Share on other sites More sharing options...
BlueSkyIS Posted January 26, 2011 Share Posted January 26, 2011 by $name method do you mean $name variable?? there probably should be no -f in this: $header = 'From: $name <$email>' . "\r\n"; Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1165569 Share on other sites More sharing options...
mark103 Posted January 26, 2011 Author Share Posted January 26, 2011 yes, sorry it was my mistake. However, I have got an email that come with a $name as sender name and <[email protected]> as my email. I have input the values into $name as sender name and $email as from sender email address. Do you know what the problem is? Here's the update code: if(isset($email)){ $name = $_GET['name']; $email = $_GET['email']; $header = 'From: $name <$email>' . "\r\n"; $to = "[email protected]"; $subject = $type; $message = "$comments & $rate"; $header .= "MIME-Version: 1.0\l\n"; mail($to, $subject, $message, $header); echo "Thank you for sent us your email"; } Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1165571 Share on other sites More sharing options...
blew Posted January 26, 2011 Share Posted January 26, 2011 try using double quotes $header = "From: $name etc"; it should work, cuz a variable only works in double quote, not in a single quote Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1165709 Share on other sites More sharing options...
BlueSkyIS Posted January 26, 2011 Share Posted January 26, 2011 try using double quotes $header = "From: $name etc"; it should work, cuz a variable only works in double quote, not in a single quote good catch! ay caramba! such a simple thing, and I missed it, even using single-quotes in my suggestion... Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1165725 Share on other sites More sharing options...
blew Posted January 27, 2011 Share Posted January 27, 2011 try using double quotes $header = "From: $name etc"; it should work, cuz a variable only works in double quote, not in a single quote good catch! ay caramba! such a simple thing, and I missed it, even using single-quotes in my suggestion... oh yeah but lets wait for the mark's answer Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1165744 Share on other sites More sharing options...
mark103 Posted January 27, 2011 Author Share Posted January 27, 2011 Thanks for the help guys. I can see the problem is fixed. However, how i can hide the mailed-by server name, something is like myservername.com. How I can get rid it?? here's the update code: if(isset($email)){ $name = $_GET['name']; $email = $_GET['email']; $header = "From: $name <$email>". "\r\n"; $to = "[email protected]"; $subject = $type; $message = "$comments & $rate"; $header .= "MIME-Version: 1.0\l\n"; $add = "$name <$email>"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your email"; } Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1165746 Share on other sites More sharing options...
mark103 Posted January 27, 2011 Author Share Posted January 27, 2011 do anyone know how to correct the problem?? Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1166013 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 not sure it can be done. warning: you might find that if you use a return address that has a different domain than the sending server your email will be bounced back, put into the spam box, and/or cause your server to be blacklisted as a spam server. i suggest that you use the actual server domain for outbound emails. Link to comment https://forums.phpfreaks.com/topic/225764-how-to-send-mail-with-name-and-email/#findComment-1166015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.