Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/137716-php-mailer/
Share on other sites

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!

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719898
Share on other sites

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") ; 

?>

Link to comment
https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719909
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/137716-php-mailer/#findComment-719922
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.