Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 7th, 2005, 5:03 PM   #1
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Working with mail function

I'm in the process of learnig php and I want to practice with the mail function but not sure how to set it up since I am set-up on the network at work running exchange server. I set up Apache web server on my pc to practice what I'm learning but now I want to be able to send my forms to an e-mail account.

I talked to a co-worker who says I have to set up a pop3 client on my local pc. Is there an easier way to do this?
dmorales is offline   Reply With Quote
Old Feb 7th, 2005, 6:34 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Yep, there sure is. Don't. It should just work by default...
__________________

tempest is offline   Reply With Quote
Old Feb 7th, 2005, 7:22 PM   #3
scorpiosage
Programmer
 
scorpiosage's Avatar
 
Join Date: Aug 2004
Location: Austin, Tx
Posts: 55
Rep Power: 4 scorpiosage is on a distinguished road
Send a message via AIM to scorpiosage Send a message via Yahoo to scorpiosage
Here's some code for ya.

This should work just fine.

 
<?
$f_name = $_POST[f_name];
$l_name = $_POST[l_name];
$phone = $_POST[phone];
$email = $_POST[email];
$additional = $_POST[additional];
$message = "Name: $f_name $l_name\r\n
Phone: $phone\r\n
";
	
	$headers = "From:  $email\n"; 
	
	
	ini_set(sendmail_from, $email);
	mail('mail@yourdomain.com','subject',$message, $headers);	
?>

This is of course assuming that there is a form to fill out beforehand that uses the post method.
To help you out here the last line of code,

 
mail('mail@yourdomain.com','subject',$message, $headers);
The email address is the email address to where it is being sent, you can change this to become a variable dependant on the prior form as well. The subject can also be replaced with whatever you want it to say, or also be a variable.
I hope this helps
Mike
__________________
Here's my latest project still in the works, and I need to get rid of this &quot;frame&quot; situation for real. www.prideofaustin.com

Last edited by scorpiosage; Feb 7th, 2005 at 7:28 PM. Reason: code didn't work right
scorpiosage is offline   Reply With Quote
Old Feb 10th, 2005, 9:57 AM   #4
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
oK mayber you can show me where my mistake is in my code.

<?
$msg = "E-MAIL SENT FROM WWW SITE\N";

$msg .= "Sender's Name:\t$_POST[sender_name]\n";

$msg .= "Sender's E-Mail:\t$_POST[sender_email]\n"

$msg .= "Message:\t$_POST[message]\n\n";

$to = "david.morales@anchortechnology.com";

$subject = "Web Site Feedback";

$mailheaders = "From: My Web Site <> \n";

ini_set(sendmail_from, david.morales@anchortechnology.com);

mail($to, $subject, $msg, $mailheaders);

?>

<HTML>
<HEAD>
<TITLE>Simple Feedback Form Sent</TITLE>
</HEAD>
<BODY>

<H1>The following e-mail has been sent:</H1>

<P><strong>Your Name:</strong><br>
<? echo "$_POST[sender_name]"; ?>

<P><strong>Your E-Mail Address:</strong><br>
<? echo $_POST[sender_email]"; ?>

<P><strong>Message:</strong><br>
<? echo "$_POST[message]"; ?>

</BODY>
</HTML>
dmorales is offline   Reply With Quote
Old Feb 10th, 2005, 12:52 PM   #5
ArchAngel
Programmer
 
ArchAngel's Avatar
 
Join Date: Jan 2005
Location: I could be anywhere, even Indiana
Posts: 34
Rep Power: 0 ArchAngel is on a distinguished road
Send a message via AIM to ArchAngel Send a message via MSN to ArchAngel Send a message via Yahoo to ArchAngel
This is more to the side, but line 6 doesn't have a ; at the end, also on line 16 you have an unexpected '@' sign.
__________________
People say I'm crazy, but I have the heart of a little boy. It's in my desk at home.

Last edited by ArchAngel; Feb 10th, 2005 at 12:57 PM.
ArchAngel is offline   Reply With Quote
Old Feb 11th, 2005, 7:19 AM   #6
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
I fix your code and commented your mistakes...
look at it and with my comments change your original... hope it helps

-codetaino[PHP]<?
//i added this in order to test your code, delete it!!
$_POST['sender_name'] = "LUIS";
$_POST['sender_email'] = "LUISARM8@HOTMAIL.COM";
$_POST['message']= "HELLO";
// end of added to test delete until here

$msg = "E-MAIL SENT FROM WWW SITE\N";
//when you call things inside the array post, get ,etc you have to send an string as the index
//i changed $_POST[sender_name] to $_POST['sender_name'];
//also when calling an array withing the string use brackets in order to make it work
$msg .= "Sender's Name:\t{$_POST['sender_name']}\n";
//same process
$msg .= "Sender's E-Mail:\t{$_POST['sender_email']}\n";
//same process
$msg .= "Message:\t{$_POST['message']}\n\n";
//replace with your email again
$to = "luisarm8@hotmail.com";

$subject = "Web Site Feedback";

$mailheaders = "From: My Web Site <> \n";
//this funciton takes two parameters and both or them are strings so i changed
//ini_set(sendmail_from,youremail@email.com) to<br>
//ini_set('sendmail_from','youremail@email.com)
//** please replace my mail with yours
ini_set('sendmail_from', 'luisarm8@hotmail.com' );

mail($to, $subject, $msg, $mailheaders);

?>

<HTML>
<HEAD>
<TITLE>Simple Feedback Form Sent</TITLE>
</HEAD>
<BODY>

<H1>The following e-mail has been sent:</H1>

<P><strong>Your Name:</strong><br>
<? //again i added the '' to the array key and also eliminated the double quotemarks " ".
// when you are sending just a variable you dont have to use the double quotemarks " ";
echo $_POST['sender_name']; ?>

<P><strong>Your E-Mail Address:</strong><br>
<? echo $_POST['sender_email']; //same?>

<P><strong>Message:</strong><br>
<? echo $_POST['message']; //same?>

</BODY>
</HTML>[/PHP]
__________________
"God bless u all" :)
codetaino is offline   Reply With Quote
Old Feb 11th, 2005, 3:15 PM   #7
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
This is the error I've been getting no matter what I try. The form Works just not the mail function.

"Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in c:\program files\easyphp1-7\www\send_simpleform.php on line 18"
dmorales is offline   Reply With Quote
Old Feb 11th, 2005, 3:17 PM   #8
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Here is the code I have now after making codetaino's changes:
<?
$msg = "E-MAIL SENT FROM WWW SITE\N";

$msg .= "Sender's Name:\t{$_POST['sender_name']}\n";

$msg .= "Sender's E-Mail:\t{$_POST['sender_email']}\n";

$msg .= "Message:\t{$_POST['message']}\n\n";

$to = "david.morales@anchortechnology.com";

$subject = "Web Site Feedback";

$mailheaders = "From: My Web Site <> \n";

ini_set('sendmail_from', 'david_anchor@hotmail.com');

mail($to, $subject, $msg, $mailheaders);

?>

<HTML>
<HEAD>
<TITLE>Simple Feedback Form Sent</TITLE>
</HEAD>
<BODY>

<H1>The following e-mail has been sent:</H1>

<P><strong>Your Name:</strong><br>
<? echo $_POST['sender_name']; ?>

<P><strong>Your E-Mail Address:</strong><br>
<? echo $_POST['sender_email']; ?>

<P><strong>Message:</strong><br>
<? echo $_POST['message']; ?>

</BODY>
</HTML>
dmorales is offline   Reply With Quote
Old Feb 12th, 2005, 8:30 AM   #9
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
ok, to be able to send emails with the mail function you have to setup the mail smtp server in the php.ini in your case it is setup to localhost... if you did this on purpose you need to download a free or paid email server. Otherwise, change the php ini entry to other smtp server available to you. Probably the one from you web hosting or internet service provider.

To change it open the php.ini with notepad (mostly located on the windows folder) search on the document for "smtp" and change it from localhost to the new smtp server.

hope my explanation helps you

-codetaino
__________________
"God bless u all" :)
codetaino is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:42 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC