bugzy Posted March 29, 2012 Share Posted March 29, 2012 I have this code as my session_init.php <?php $_SESSION['APP_MX'] = "mail.mywebsite.com"; $_SESSION['APP_SERVER'] = "mywebsite.com"; $_SESSION['SITE_EMAIL'] = "admin@mywebsite.com"; $_SESSION['MYSQL_SERVER1'] = "localhost"; $_SESSION['MYSQL_LOGIN1'] = "root"; $_SESSION['MYSQL_PASS1'] = "password"; $_SESSION['MYSQL_DB1'] = "sample"; $_SESSION['LOGGEDIN'] = ""; $_SESSION['USERID'] = 0; $_SESSION['EMAIL'] = ""; $_SESSION['FNAME'] = ""; $_SESSION['LNAME'] = ""; $_SESSION['SESSION'] = true; ?> and I'm calling it here <?php if(!isset($_SESSION['SESSION'])) require('../email/session_init.php'); $fname = $_POST["fname"]; $lname = $_POST["lname"]; $email= $_POST["email"]; $company = $_POST["company"]; $subject = $_POST["subject"]; $phone = $_POST["phone"]; $msg = $_POST["msg"]; $mail = "Hello $fname,\n\nThank your for your email.\nWe look forward to your evaluation of our product.\n\n"; $mail .= "Here is the information you have given us:\n\n"; $mail .= "Name: ".$fname." ".$lname."\n"; $mail .= "Company: ".$company."\n"; $mail .= "Email Address: ".$email."\n"; $mail .= "Phone: ".$phone."\n\n"; $mail .= "Subject: ".$subject."\n"; $mail .= "Your Message:\n".$msg."\n\n\n"; $mail .= "Best Regards,\nCustomer Service\n\n"; // If any lines are larger than 70 characters, we will use wordwrap() $message = wordwrap($msg, 70); mail($email, $subject, $mail, "From: admin@".$_SESSION['APP_SERVER']."\r\n"); $mail = str_replace("\n", "<br>", $mail); ?> And I'm getting this error Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 26, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\php\website_interactivity\email\email_sent.php on line 33 I wonder if there's any modification that I need to do in my php.ini file. Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/ Share on other sites More sharing options...
trq Posted March 29, 2012 Share Posted March 29, 2012 OT but, Why on earth are you storing that data in a users $_SESSION? That is application specific data, the $_SESSION is *client* specific. You will have duplicate copies of the same data for every user on your site for no good reason. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332318 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 OT but, Why on earth are you storing that data in a users $_SESSION? That is application specific data, the $_SESSION is *client* specific. You will have duplicate copies of the same data for every user on your site for no good reason. Hey thanks for the advise there. I'm just new and I'm just trying things out. My main concern is this email issue I'm getting.... Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332321 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 standard port for SMTP is port 25, not 26. The only reason it would be looking at 26 is if you had already altered your php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332322 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2012 Share Posted March 29, 2012 Failed to connect to mailserver at "localhost" ^^^ Do you have a mail server installed and running on your localhost Windows computer that is listening on that port number? The php mail function acts like a simple unauthenticated email client (i.e. Outlook/Thunderbird but without a username/password.) It needs a locally installed mail server (that it accesses through a command line interface - sendmail) or an SMTP mail server that has been configured to trust the IP address of the web server that your php script is running on. Do you actually need to send email from your localhost computer or are you just trying to test a script that uses the mail() function in it? Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332324 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 Failed to connect to mailserver at "localhost" ^^^ Do you have a mail server installed and running on your localhost Windows computer that is listening on that port number? The php mail function acts like a simple unauthenticated email client (i.e. Outlook/Thunderbird but without a username/password.) It needs a locally installed mail server (that it accesses through a command line interface - sendmail) or an SMTP mail server that has been configured to trust the IP address of the web server that your php script is running on. Do you actually need to send email from your localhost computer or are you just trying to test a script that uses the mail() function in it? Hey thanks for the quick response. No, I'm not trying to send a mail on my localhost computer. But I do have an email server from another server. with an incoming mail server at: mail.mysamplewebsite.com Sorry for my ignorance on this as I'm just starting to learn php. Is there a simple way to do it. I'm basing that code from a video tutorial I have here and maybe they set it up for a local machine... Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332332 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2012 Share Posted March 29, 2012 But I do have an email server from another server. Network-wise, what is the relationship between your localhost computer and where the mail server is at? Are they on the same local network AND the mail server has been configured to trust the IP address of your localhost web server or are they on completely separate networks, such as your mail server is at your ISP or a web host and your localhost computer is at your office or home? A general purpose solution would be to use one of the popular php mailer classes and use SMTP Authentication (i.e. supply a username/password for a mail box on that mail server), because the php mail() function does not support SMTP Authentication. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332356 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 But I do have an email server from another server. Network-wise, what is the relationship between your localhost computer and where the mail server is at? Are they on the same local network AND the mail server has been configured to trust the IP address of your localhost web server or are they on completely separate networks, such as your mail server is at your ISP or a web host and your localhost computer is at your office or home? A general purpose solution would be to use one of the popular php mailer classes and use SMTP Authentication (i.e. supply a username/password for a mail box on that mail server), because the php mail() function does not support SMTP Authentication. I don't have a localhost server that is setup here right now and there's no relation with the one that I will be using which is at my web host. So to make it clear, I would be using solely the mail server which is also on my webhost. I have tried searching it on Google but it is giving a simple e-mail form w/out SMTP authentication(username & pass) like what you're saying.. Can you point me out or link me to php mailer classes that you're talking? Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332364 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2012 Share Posted March 29, 2012 I would be using solely the mail server which is also on my webhost. Then you should consult with them/their FAQ as to the hostname and port number that you should be using in your php script. If the default values in the php.ini (localhost, port 26) didn't connect to a valid mail server, then either the mail server was down at the time you tried or you are expected to set the "SMTP" and "smtp_port" settings to the correct values using ini_set() statements in your script, as the error message suggests. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332371 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 how adventurous are you feeling? You could use my old friend the PEAR Net_SMTP class for sending mail through authenticated SMTP if your feeling masachistic, or you can download a third party script library from a number of sites if you would preffer. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332373 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 I would be using solely the mail server which is also on my webhost. Then you should consult with them/their FAQ as to the hostname and port number that you should be using in your php script. If the default values in the php.ini (localhost, port 26) didn't connect to a valid mail server, then either the mail server was down at the time you tried or you are expected to set the "SMTP" and "smtp_port" settings to the correct values using ini_set() statements in your script, as the error message suggests. I have already contacted them.. and they said it is correct. Port 26 is right and my php.ini smtp is also 26. If we are going to base it on my code... notice that there's no password authentication there? maybe that's the cause of the problem? Though I don't know how and where to put it there.. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332377 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2012 Share Posted March 29, 2012 The error message you posted at the start of this thread is from a Windows/wamp system. Did that error message come from a php script running on your web host? If you are not using SMTP Authentication and the mail server requires it, you would be likely (but not always) getting errors indicating permission problems/authentication required/relaying restrictions... and your web host would have probably told you if you need to SMTP Authentication. There error message you did get indicates that there is no mail server listening on that port number (or it was not running) on the localhost computer where the web server/php is running at. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332380 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 The error message you posted at the start of this thread is from a Windows/wamp system. Did that error message come from a php script running on your web host? If you are not using SMTP Authentication and the mail server requires it, you would be likely (but not always) getting errors indicating permission problems/authentication required/relaying restrictions... and your web host would have probably told you if you need to SMTP Authentication. There error message you did get indicates that there is no mail server listening on that port number (or it was not running) on the localhost computer where the web server/php is running at. Alright! So the easiest way to do it is by using PEAR Net_SMTP class? and I need to install it right? Is there anyway possible you can code an e-mail form with a smpt authentication without using 3rd party class? Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332387 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2012 Share Posted March 29, 2012 So the easiest way to do it is by using PEAR Net_SMTP class? and I need to install it right? No. That's why Muddy_Funster suggested doing so would be masochistic. You first need to determine what requirements there are and why it is not working now. You could go through the trouble of using a phpmailer class only to learn that there is a problem with a firewall between your web server and the mail server. Is there anyway possible you can code an e-mail form with a smpt authentication without using 3rd party class? Does your web host have any FAQ information available? If they gave you information about the mail server's hostname, mail.mysamplewebsite.com, you should be using that as the "SMTP" setting instead of 'localhost'. Yes, you can open a socket connect to the mail server and directly send and parse smtp commands and replies (this is what the phpmailer classes do for you.) Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332395 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 Not if it's windows baised, PHP sendmail can handle SMTP authentication on a linux server, by altering the php.ini file to include it, but it's not supported in a windows environment. And PEAR Net_SMTP isn't even close to the easiest way to get the job done (in fact I don't think they could see each other with a telescope!), using some well documented third party stuff would probably be easier. If you do opt for the PEAR rout you'll find a heavily commented mail function on my blog page in my sig that you are free to use and abuse to suit your needs, it should take a little bit of the pain out of it (not much mind you). Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332396 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 Ok guys! Thank you very much. I'm gonna just find another way to do an e-mail form and code it myself. Will get back to this thread if I encounter a code problem. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332402 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 good luck with that, I hope your running on a Linux server, because (and I speek from experience) there just isn't an easy way to code it yourself on Windows. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332406 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 good luck with that, I hope your running on a Linux server, because (and I speek from experience) there just isn't an easy way to code it yourself on Windows. Hey I totally agree. It was really a pain in the @ss. I thought this is just a simple in php. Anyway I finally get it working with smtp authentication, though the feature is just sending an e-mail to me using my own e-mail(to) and my another email (from). So basically visitors will just input their information the feedback form page and it will send it to me. This is the code that I used: <?php //new function $to = "you@your-domainname.com"; $nameto = "Who To"; $from = "script@your-domainname.com"; $namefrom = "Who From"; $subject = "Hello World Again!"; $message = "World, Hello!"; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <?php /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */ //This will send an email using auth smtp and output a log array //logArray - connection, function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) { //SMTP + SERVER DETAILS /* * * * CONFIGURATION START * * * */ $smtpServer = "mail.ukdns.biz"; $port = "25"; $timeout = "30"; $username = "your-email-address@domain.com"; $password = "Your-POP3-Password"; $localhost = "mail.ukdns.biz"; $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"; //insert var_dump here -- uncomment out the next line for debug info //var_dump($logArray); } ?> What do you think of it? anyone? Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332437 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 if it does the job PS - I see your now using port 25...... Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332438 Share on other sites More sharing options...
bugzy Posted March 29, 2012 Author Share Posted March 29, 2012 if it does the job PS - I see your now using port 25...... Hey it was actually port 26. I just forgot to edit it. Anyway thanks for those who help me out here. Quote Link to comment https://forums.phpfreaks.com/topic/259942-cant-get-e-mail-form-to-work/#findComment-1332441 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.