![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Yep, there sure is. Don't. It should just work by default...
__________________
|
|
|
|
|
|
#3 |
|
Programmer
|
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);I hope this helps Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com Last edited by scorpiosage; Feb 7th, 2005 at 7:28 PM. Reason: code didn't work right |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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> |
|
|
|
|
|
#5 |
|
Programmer
|
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. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4
![]() |
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" :) |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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" |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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> |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4
![]() |
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" :) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|