Birdmansplace Posted February 16, 2010 Share Posted February 16, 2010 Been trying to figure out why my code doesnt work. It did when i first put it together but now for some reason nothing happens. T Any Ideas. Have a feeling i am missing something that i cant see like normal. Thanks for the help ahead of time! form code: <form method="post" action="sendemail.php"> <h3>Email Me</h3> <!-- DO NOT change ANY of the php sections --> Your Name: <br> <input type="text" name="to" size="35" /> <br><br> Your Email: <br> <input type="text" name="email" size="35" /> <br> <br> <br> Attention: <br> <select name="attn" size="1"> <option value=" Sales n Billing ">Sales n Billing </option> <option value=" Attaining Services ">Attaning Services </option> <option value=" Questions/Quote ">Questions/Quote </option> <option value=" Webmaster ">Webmaster </option> </select> <br><br> Mail Message: <br> <textarea name="notes" rows="4" cols="40"></textarea> <br> <input type="submit" value="Send Mail" /> <br> </form> sendemail.php: <?php $from = $_POST['email']; $namefrom = $_POST['to']; $to = "me@mydomain.com"; $nameto = "websitescript"; $subject = $_POST['attn']; $message = $_POST['notes']; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <?php /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */ ini_set("display_errors", "1"); error_reporting(E_ALL); function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) { //SMTP + SERVER DETAILS /* * * * CONFIGURATION START * * * */ $smtpServer = "smtpserver"; $port = "25"; $timeout = "30"; $username = "smtpusername"; $password = "smtppassrd"; $localhost = "localhost"; $newLine = "\r\n"; /* * * * CONFIGURATION END * * * * */ //Connect to the host on the specified port $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout); $smtpResponse = fgets($smtpConnect, 515); if(empty($smtpConnect)) { $output = "Failed to connect: $smtpResponse"; return $output; } else { $logArray['connection'] = "Connected: $smtpResponse"; } //Request Auth Login fputs($smtpConnect,"AUTH LOGIN" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authrequest'] = "$smtpResponse"; //Send username fputs($smtpConnect, base64_encode($username) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authusername'] = "$smtpResponse"; //Send password fputs($smtpConnect, base64_encode($password) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authpassword'] = "$smtpResponse"; //Say Hello to SMTP fputs($smtpConnect, "HELO $localhost" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['heloresponse'] = "$smtpResponse"; //Email From fputs($smtpConnect, "MAIL FROM: $from" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['mailfromresponse'] = "$smtpResponse"; //Email To fputs($smtpConnect, "RCPT TO: $to" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['mailtoresponse'] = "$smtpResponse"; //The Email fputs($smtpConnect, "DATA" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['data1response'] = "$smtpResponse"; //Construct Headers $headers = "MIME-Version: 1.0" . $newLine; $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine; $headers .= "To: $nameto <$to>" . $newLine; $headers .= "From: $namefrom <$from>" . $newLine; fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n"); $smtpResponse = fgets($smtpConnect, 515); $logArray['data2response'] = "$smtpResponse"; // Say Bye to SMTP fputs($smtpConnect,"QUIT" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['quitresponse'] = "$smtpResponse"; } ?> <?php $from = $_POST['email']; $namefrom = $_POST['to']; $to = "birdman@birdmansplace.com"; $nameto = "websitescript"; $subject = $_POST['attn']; $message = $_POST['notes']; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <div align="center"> <br /> <br /> <br /> <br /> <br /> <br /> <? echo "Your message has been sent $namefrom"; echo "<br />"; echo "Print this page for your records if you want"; echo "<br />"; echo "Subjest: $subject"; echo "<br />"; echo "<br />"; echo "Message: $message"; ?> Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 16, 2010 Author Share Posted February 16, 2010 Anyone see anything wrong atleast? Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 16, 2010 Author Share Posted February 16, 2010 Any one willing to give me a hand. Been hours workin on this and still no where yet? Quote Link to comment Share on other sites More sharing options...
samtwilliams Posted February 16, 2010 Share Posted February 16, 2010 Have you looked at the mail() function within php? Or is their a specific reason for using smtp? Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 16, 2010 Author Share Posted February 16, 2010 mail() function sends more than one email no matter what i do. I have found at least for me that using smtp sends one and only one email. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 17, 2010 Author Share Posted February 17, 2010 I could use some help here. Does my code even look correct? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 17, 2010 Share Posted February 17, 2010 hai i dont see your code, but you can try this code. i am sure this will work quite good.. u require Pear to be installed in your machine for this to work.. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 17, 2010 Author Share Posted February 17, 2010 its in the first post Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 17, 2010 Share Posted February 17, 2010 its in the first post i didnt got it Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 17, 2010 Author Share Posted February 17, 2010 my code works just fine but trying to figure out why its not sending the email let alone if its collecting the info before it sends. It does connect. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 17, 2010 Author Share Posted February 17, 2010 Been trying to figure out why my code doesnt work. It did when i first put it together but now for some reason nothing happens. T Any Ideas. Have a feeling i am missing something that i cant see like normal. Thanks for the help ahead of time! form code: <form method="post" action="sendemail.php"> <h3>Email Me</h3> <!-- DO NOT change ANY of the php sections --> Your Name: <br> <input type="text" name="to" size="35" /> <br><br> Your Email: <br> <input type="text" name="email" size="35" /> <br> <br> <br> Attention: <br> <select name="attn" size="1"> <option value=" Sales n Billing ">Sales n Billing </option> <option value=" Attaining Services ">Attaning Services </option> <option value=" Questions/Quote ">Questions/Quote </option> <option value=" Webmaster ">Webmaster </option> </select> <br><br> Mail Message: <br> <textarea name="notes" rows="4" cols="40"></textarea> <br> <input type="submit" value="Send Mail" /> <br> </form> sendemail.php: <?php $from = $_POST['email']; $namefrom = $_POST['to']; $to = "me@mydomain.com"; $nameto = "websitescript"; $subject = $_POST['attn']; $message = $_POST['notes']; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <?php /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */ ini_set("display_errors", "1"); error_reporting(E_ALL); function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) { //SMTP + SERVER DETAILS /* * * * CONFIGURATION START * * * */ $smtpServer = "smtpserver"; $port = "25"; $timeout = "30"; $username = "smtpusername"; $password = "smtppassrd"; $localhost = "localhost"; $newLine = "\r\n"; /* * * * CONFIGURATION END * * * * */ //Connect to the host on the specified port $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout); $smtpResponse = fgets($smtpConnect, 515); if(empty($smtpConnect)) { $output = "Failed to connect: $smtpResponse"; return $output; } else { $logArray['connection'] = "Connected: $smtpResponse"; } //Request Auth Login fputs($smtpConnect,"AUTH LOGIN" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authrequest'] = "$smtpResponse"; //Send username fputs($smtpConnect, base64_encode($username) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authusername'] = "$smtpResponse"; //Send password fputs($smtpConnect, base64_encode($password) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authpassword'] = "$smtpResponse"; //Say Hello to SMTP fputs($smtpConnect, "HELO $localhost" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['heloresponse'] = "$smtpResponse"; //Email From fputs($smtpConnect, "MAIL FROM: $from" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['mailfromresponse'] = "$smtpResponse"; //Email To fputs($smtpConnect, "RCPT TO: $to" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['mailtoresponse'] = "$smtpResponse"; //The Email fputs($smtpConnect, "DATA" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['data1response'] = "$smtpResponse"; //Construct Headers $headers = "MIME-Version: 1.0" . $newLine; $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine; $headers .= "To: $nameto <$to>" . $newLine; $headers .= "From: $namefrom <$from>" . $newLine; fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n"); $smtpResponse = fgets($smtpConnect, 515); $logArray['data2response'] = "$smtpResponse"; // Say Bye to SMTP fputs($smtpConnect,"QUIT" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['quitresponse'] = "$smtpResponse"; } ?> <?php $from = $_POST['email']; $namefrom = $_POST['to']; $to = "birdman@birdmansplace.com"; $nameto = "websitescript"; $subject = $_POST['attn']; $message = $_POST['notes']; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <div align="center"> <br /> <br /> <br /> <br /> <br /> <br /> <? echo "Your message has been sent $namefrom"; echo "<br />"; echo "Print this page for your records if you want"; echo "<br />"; echo "Subjest: $subject"; echo "<br />"; echo "<br />"; echo "Message: $message"; ?> Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 17, 2010 Share Posted February 17, 2010 ohhh it is not that i cannot see ur code.. i didnt tested it out in my machine thatz what i was saying..lol... Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 17, 2010 Author Share Posted February 17, 2010 the first part of the sendmail.php code was this: <?php //Randy Bird $to = "toemail@domainl.com"; $nameto = "nameto"; $from = "fromemail@domain.com"; $namefrom = "namefrom"; $subject = "emailsubject"; $message = "emailmessage"; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> I made changes to this so the code would read the form info and send it: <?php $from = $_POST['email']; $namefrom = $_POST['to']; $to = "email@domain.com"; $nameto = "websitescript"; $subject = $_POST['attn']; $message = $_POST['notes']; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> the way i have it set up is the form will connect to one of my domain email address's and send to another. while doing it this way i do get the users email address along with it. So: user enters info - - - send - - - - emailA connects and logs in - - - sends to emailB. both emailA,B are both in my domain Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted February 18, 2010 Author Share Posted February 18, 2010 hai i dont see your code, but you can try this code. i am sure this will work quite good.. u require Pear to be installed in your machine for this to work.. I use debian lenny and have no clue other than the fact that i have it installed along with php-net-smtp, php-net-socket, php-mail. And now that i have done all this testing and crap my ip as been blocked and reported as a spam ip. Been googling for hours and well i am still stuck. I am a newb when it comes to email. I am trying to get a contact form for my site so i dont have to display my email address. The account i have setup has an auto reply so the user gets a reply to know it got through. This is the last thing to do before i am done hopefully. Thanks 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.