diode Posted January 16, 2007 Share Posted January 16, 2007 Hello,What I am making is an account registration part of my website. The registration form works and it submits it to the next page and all that. But on the page it submits it to, I'm making it so that it inserts a row into a table using MySQL and adds them to the users table so that they can log in and use the site and stuff. The variables I'm using on this initial account creation are:$firstname$lastname$acctname$password$emailI want to send them an email from the page that receives the form, to show them their account details, and provide a link for them to click on to activate the account. But I can't get the email sender thing to work. I'm sure it's probably something easy, but I couldn't find it in the PHP Manual that came with my php.Thanks in advance :),diode Quote Link to comment Share on other sites More sharing options...
diode Posted January 16, 2007 Author Share Posted January 16, 2007 Oh yeah, forgot to add, that I tried searching the topics on here, and didn't find what I was looking for.diode Quote Link to comment Share on other sites More sharing options...
Tandem Posted January 16, 2007 Share Posted January 16, 2007 Try this code:[code]$email = "email address here";$subject = "subject here"; $message = "Message Here";$headers = "From: blah@blah.com\r\n";mail($email, $subject, $message, $headers)or die('There has been an error, please try again.');[/code] Quote Link to comment Share on other sites More sharing options...
diode Posted January 17, 2007 Author Share Posted January 17, 2007 It's not working. Does this work like sending a form to email? Or do I need an email daemon running on my server? The browser does not show any errors, but I do not receive any email.Thanks,diode Quote Link to comment Share on other sites More sharing options...
diode Posted January 18, 2007 Author Share Posted January 18, 2007 I have tried everything suggested here, and it's still not working. What are the requirements in order to email information from a php page to somebody? For example, do I need certain daemons running, other things installed, etc.Thanks :),diode Quote Link to comment Share on other sites More sharing options...
Nhoj Posted January 19, 2007 Share Posted January 19, 2007 What type of server are you running, something from your home or something you are paying for like shared hosting? Does that host have cPanel?If your running from a shared host with PHP and apache you can do something like....[code=php:0] $subject = 'MY SUBJECT'; $message = '<html><body>my html message</body></html>'; $headers = 'MIME-Version: 1.0'."\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; $headers .= 'Return-Path: YOURMAIL@DOMAIN.COM'."\r\n"; $headers .= 'From: YOUR NAME <YOURMAIL@DOMAIN.COM>'; mail('SENDTO@DOMAIN.COM', $subject, $message, $headers, "-f YOURMAIL@DOMAIN.COM");[/code]In order for AOL users or even some other mail clients such as hotmail you might need to have Reverse DNS enabled on your server. You'll need to talk to your host about that one. Quote Link to comment Share on other sites More sharing options...
kemper Posted January 19, 2007 Share Posted January 19, 2007 What is the error that you are getting? Quote Link to comment Share on other sites More sharing options...
whitelion Posted January 19, 2007 Share Posted January 19, 2007 simple code for sending email with HTML :[code=php:0]<?php // Recipients. You can send it to more than 1 person! $to = "you1 <you@yoursite.com>" . ", " ; // note the comma $to .= "you2 <you2@yoursite.com>"; // This is the email subject $my_subject = "My first HTML message!"; // Message $my_message = ' <html> <head> <title>My first HTML message!</title> </head> <body> <table> <tr> <td>Hi! Just to say i can now send html mail :p</td> </tr> <tr> <td>Do you like it!? C ya</td> </tr> </table> </body> </html> '; // To send HTML mail, you can set the Content-type header. $my_headers = "MIME-Version: 1.0rn"; $my_headers .= "Content-type: text/html; charset=iso-8859-1rn"; // Setting additional headers $my_headers .= "From: HTML mail <example@example.com>rn"; $my_headers .= "Cc: example@example.comrn"; $my_headers .= "Bcc: example@example.comrn"; // And now mail it! mail($to, $my_subject, $my_message, $my_headers); ?>[/code]Or read more in here :http://www.t4vn.net/example/showcode/Sending-HTML-email.html Quote Link to comment Share on other sites More sharing options...
diode Posted January 20, 2007 Author Share Posted January 20, 2007 Sorry to everyone who I haven't responded to. I was out of town last night and had to work today. It's my own personal server in my room. It is a 400 mhz Power Mac G4 running MAMP. Mac OS X 10.4.8, Apache, PHP, and MySQL. I get no error message. It acts like it has sent the mail, and yet I receive nothing. In the "From" field, I don't know what to put. How would I check to see if I have an email daemon running? I can't remember the unix command to do it. This is, of course, if I really need an email daemon. Do I have to have a working email address to send the data? And does it have to be a daemon on the server sending it?Thanks a lot for your time :),diode Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 You need sendmail. Did you read the php.net/mail page? Quote Link to comment Share on other sites More sharing options...
diode Posted January 20, 2007 Author Share Posted January 20, 2007 Not yet. I'm going to do that now.diode Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 Always read the manual. Quote Link to comment Share on other sites More sharing options...
diode Posted January 20, 2007 Author Share Posted January 20, 2007 Wow do I feel stupid...I forgot PHP was like its own site...:P Quote Link to comment Share on other sites More sharing options...
linuxdream Posted January 20, 2007 Share Posted January 20, 2007 Don't forget that if it's your own server, your ISP may not let you send anything with a destination port of 25...which would be any email. That's why I can't send email anyway... Just though I would mention it.B Quote Link to comment Share on other sites More sharing options...
diode Posted January 21, 2007 Author Share Posted January 21, 2007 Well here's my code, and I still can't send emails.[code]<?php$email = $_POST['email'];$fromaddress = "do-not-reply@myserveripaddress";$eol="\r\n";$mime_boundary=md5(time()); $headers .= 'From: Boards<'.$fromaddress.'>'.$eol; $headers .= 'Reply-To: Do Not Reply<'.$fromaddress.'>'.$eol; $headers .= 'Return-Path: Boards<'.$fromaddress.'>'.$eol; // these two to set reply address $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'.$eol; $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;$subject = "Account registration";$msg = "Thank you for registering for the message boards.$eol $eol---------------------------------$eol Here is your account information:$eol First name:\t$firstname $eol Last name:\t$lastname $eol Account name:\t$acctname $eol Password:\t$password $eol Email address:\t$email\n--------------------------------------------$eol $eol To activate your account, click this link, or enter it in your browser's address bar and go to it.\t\t pagename.php $eol $eol Observe reasonable conduct and enjoy the message boards!";ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !mail($email, $subject, $msg, $headers);ini_restore(sendmail_from);echo " A registration email has been sent to the email address you specified. To activate your account, you must check your email and click on the link provided. Thank you and enjoy the message boards.";?>[/code]It turns out I do have sendmail installed. SMTP is set to localhost. smtp_port is 25 in phpinfo().Is it even possible for this to work? lol... Thanks :),diode Quote Link to comment Share on other sites More sharing options...
smc Posted January 21, 2007 Share Posted January 21, 2007 Now this is going to be ironic since I own a web hosting company and frown upon this but another possibility for you is to have your own php scripts and all of that on your server and then get a free hosting from a web hosting company supporting PHP/MySQL/cPanel.Generally you can find one that offers little amounts of space but it won't take up much for sendmail. Then all you need to do is have your script on your own server send that command (or include it) to the server in cyberspace which sends the e-mail and then inturn redirects you back to your server.You can see specifics for the cPanel configuration you'll need at http://xpsservers.com but don't try signing up for a free one, I'm already onto you ;)Hope this helps,-SMC Quote Link to comment Share on other sites More sharing options...
diode Posted January 21, 2007 Author Share Posted January 21, 2007 Wow, thanks for the info SMC. I'm honorable and won't take advantage of your site since you provided me free and valuable information. So then my isp is preventing me from sending the emails? :(diode Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Share Posted January 21, 2007 ok, this is what ive had to do for my normal server.......ive had to port forward port 81 ( any port you want will work becauase my isp blocks port 80 outgoing ( or shaterver) ( port 80 is defult http)) and then get people to type :81 after the url...........now they also block port 25.... outgoing only for hosting becauase they use that port for their mail... so i am going to use mercury mailserver.... free and came with xampp, so i thinnk all i d ghave to do is port forward another prot and then set email to go to the mail server.... and redirect to outside world.... through another port....i think that should help Quote Link to comment 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.