ririe44 Posted December 19, 2008 Share Posted December 19, 2008 Hey everyone! I'm hoping there's a solution to my problem. I have the following code which supports my new mailer, but I'd like to make a custom "From" part that I could put my sites name, or something... right now it is from my "$adminaddress", and I'd prefer to have it say something like "$sitename Form". From what I understand about mail(), it's mail(to, subject, content)... but nothing for a "from"... Let me know, thanks! mail ("$adminaddress","$subject", "A visitor at $sitename has left the following information\n Email: $sender\n The visitor commented: ------------------------------ $message Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/ Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 change this: ("$adminaddress","$subject", to this; ("$sitename form","$subject", Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719855 Share on other sites More sharing options...
ririe44 Posted December 19, 2008 Author Share Posted December 19, 2008 But then it wouldn't get to me... The script wouldn't have anywhere to go... except to the $sitename, right? Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719883 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 $adminaddress = $sitename . " <" . $adminaddress . ">"; Should work. Edit: Switched < and > to be correct. Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719885 Share on other sites More sharing options...
ririe44 Posted December 19, 2008 Author Share Posted December 19, 2008 Okay, I'm attaching the full code... because this is still not making any sense to me. <? $adminaddress = "email@yourdomain.com"; $siteaddress ="http://www.yourdomain.com"; $sitename = "yourdomain.com"; //No need to change anything below ... // Gets the date and time from your server $date = date("m/d/Y H:i:s"); // Gets the IP Address if ($REMOTE_ADDR == "") $ip = "no ip"; else $ip = getHostByAddr($REMOTE_ADDR); // Gets the POST Headers - the Flash variables $sender = $HTTP_POST_VARS['sender'] ; $subject = $HTTP_POST_VARS['subject'] ; $message = $HTTP_POST_VARS['message'] ; //Process the form data! // and send the information collected in the Flash form to Your nominated email address mail ("$adminaddress","$subject", "A visitor at $sitename has left the following information\n Email: $sender\n The visitor commented: ------------------------------ $message Logged Info : ------------------------------ Using: $HTTP_USER_AGENT Hostname: $ip IP address: $REMOTE_ADDR Date/Time: $date","FROM: $adminaddress" ) ; //This sends a confirmation to your visitor mail ("$sender","Thank You for visiting $sitename", "Hi $sender,\n Thank you for contacting $sitename!\n Your message was received. Respectfully, Webmaster@$sitename $siteaddress") ; ?> So, what if I want it to be: From:$sender, To:$adminaddress, Subject:$subject... how would you change the above code? Thanks, I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719898 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 Okay, I'm attaching the full code... because this is still not making any sense to me. <?php $adminaddress = "email@yourdomain.com"; $siteaddress ="http://www.yourdomain.com"; $sitename = "yourdomain.com"; //No need to change anything below ... // Gets the date and time from your server $date = date("m/d/Y H:i:s"); // Gets the IP Address if ($REMOTE_ADDR == "") $ip = "no ip"; else $ip = getHostByAddr($REMOTE_ADDR); // Gets the POST Headers - the Flash variables $sender = $HTTP_POST_VARS['sender'] ; $subject = $HTTP_POST_VARS['subject'] ; $message = $HTTP_POST_VARS['message'] ; //Process the form data! // and send the information collected in the Flash form to Your nominated email address mail ("$adminaddress","$subject", "A visitor at $sitename has left the following information\n Email: $sender\n The visitor commented: ------------------------------ $message Logged Info : ------------------------------ Using: $HTTP_USER_AGENT Hostname: $ip IP address: $REMOTE_ADDR Date/Time: $date","FROM: $adminaddress" ) ; //This sends a confirmation to your visitor mail ("$sender","Thank You for visiting $sitename", "Hi $sender,\n Thank you for contacting $sitename!\n Your message was received. Respectfully, Webmaster@$sitename $siteaddress") ; ?> So, what if I want it to be: From:$sender, To:$adminaddress, Subject:$subject... how would you change the above code? Thanks, I really appreciate it! <?php $siteaddress ="http://www.yourdomain.com"; $sitename = "yourdomain.com"; $adminaddress = $sitename . " <email@yourdomain.com>"; //No need to change anything below ... // Gets the date and time from your server $date = date("m/d/Y H:i:s"); // Gets the IP Address if ($_SERVER['REMOTE_ADDR'] == "") $ip = "no ip"; // before assumed register_globals was on. else $ip = getHostByAddr($_SERVER['REMOTE_ADDR']); // Gets the POST Headers - the Flash variables $sender = $_POST['sender'] ; $subject = $_POST['subject'] ; $message = $_POST['message'] ; // $HTTP_POST_VARS is depreciated. //Process the form data! // and send the information collected in the Flash form to Your nominated email address mail ("$adminaddress","$subject", "A visitor at $sitename has left the following information\n Email: $sender\n The visitor commented: ------------------------------ $message Logged Info : ------------------------------ Using: {$_SERVER['HTTP_USER_AGENT']} Hostname: $ip IP address: {$_SERVER['REMOTE_ADDR']} Date/Time: $date","FROM: $adminaddress" ) ; //This sends a confirmation to your visitor mail ("$sender","Thank You for visiting $sitename", "Hi $sender,\n Thank you for contacting $sitename!\n Your message was received. Respectfully, Webmaster@$sitename $siteaddress") ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719909 Share on other sites More sharing options...
ririe44 Posted December 19, 2008 Author Share Posted December 19, 2008 Awesome! Thanks so much, it worked great! I'm still trying to analyze how it works (obviously new to this php thing...) Wanna help me with one more thing on this script? At the end, there's a confirmation email sent to the sender. Right now, the "From" address is coming from my server, but I'd rather is say "yourdomain.com", or $sitename. Is this possible? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719922 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.