deziners.studio Posted March 7, 2010 Share Posted March 7, 2010 Hello All! I am not a professional php coder and even don't have great experience in php. I was coding a feedback form on my site using php and its working on one of my server but not working on another server. When I asked about it to the hosting company they told me to use SMTP authentication it. I don't know how to use SMTP authentication in my coding. So please can anybody help me in this... You can check my code here : <?php /* This form is designed and developed by Deziners Studio*/ $c_name = $_POST['c_name']; $c_designation = $_POST['c_designation']; $c_address = $_POST['c_address']; $c_phone = $_POST['c_phone']; $c_email = $_POST['c_email']; $c_requirement = $_POST['c_requirement']; $todayis = date("l, F j, Y, g:i a") ; // Creating header for sending email to Site Administrator $header = 'From:' . $c_email . "\r\n"; // Creating subject for sending email to Site Administrator $subject = "$c_email has submitted contact request form on your site..."; // Putting Site Administrator's email id for sending email $send_to = "[email protected]"; $message = "Dear Administrator,\n\n You received career request through contact request form on $todayis [EST] from $c_email ...\n The Details are as below:\n\n <strong>$todayis [EST]</strong> \n <strong>Name :</strong> $c_name \n <strong>Designation :</strong> $c_designation \n <strong>Address :</strong> $c_address \n <strong>Phone No. :</strong> $c_phone \n <strong>Email :</strong> $c_email \n <strong>Requirement :</strong> $c_Requirement \n "; // Send message to Site Administrator $success = mail ($send_to, $subject, $message, $header); if ($success) { //Creating confirmation message to send to the user $user_email = $c_email; $from_email = "[email protected]"; $receipt_subject = "Confirmation of your career request..."; $receipt_header = 'From: ' . $from_email . "\r\n"; $receipt_message = "Dear $c_name, \n\n Your request for contact on $todayis [EST] has been received and forwarded to our concerned department. We will get back to you within 24 hours. \n Thanking you. \n\n Best Regards, \n Deziners Studio \n www.dezinersstudio.com"; // Send the confirmation mail to the user mail ($user_email, $receipt_subject, $receipt_message, $receipt_header); header('Location: success_contact.html'); } else { header('Location: contact.html'); } ?> Link to comment https://forums.phpfreaks.com/topic/194396-how-to-send-email-from-a-php-script-using-smtp-authentication/ Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 The easiest way would be to use a third party library like PHPMailer. PHP's mail function is not capable of smtp authentication. Link to comment https://forums.phpfreaks.com/topic/194396-how-to-send-email-from-a-php-script-using-smtp-authentication/#findComment-1022578 Share on other sites More sharing options...
deziners.studio Posted March 7, 2010 Author Share Posted March 7, 2010 But I don't know how to use this PHPMailer library. Can you show me sample code for it. Link to comment https://forums.phpfreaks.com/topic/194396-how-to-send-email-from-a-php-script-using-smtp-authentication/#findComment-1022584 Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 There are examples within the download and there are help forums on the projects site. I have never had the need to use such a library. Link to comment https://forums.phpfreaks.com/topic/194396-how-to-send-email-from-a-php-script-using-smtp-authentication/#findComment-1022590 Share on other sites More sharing options...
xcoderx Posted March 7, 2010 Share Posted March 7, 2010 maybe this could help? <?php //new function $to = "[email protected]"; $nameto = "Who To"; $from = "[email protected]"; $namefrom = "Who From"; $subject = "Hello World Again!"; $message = "World, Hello!" authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <?php /* SEND EMAIL FUNCTIONS */ //Authenticate Send - 21st March 2005 //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.server.com"; $port = "25"; $timeout = "30"; $username = "smtpusername"; $password = "smtppassword"; $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"; } ?> Link to comment https://forums.phpfreaks.com/topic/194396-how-to-send-email-from-a-php-script-using-smtp-authentication/#findComment-1022695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.