Recommend this page to a friend! |
Easy Email SMTP | > | All threads | > | How to setup SMTP for send email in php | > | (Un) Subscribe thread alerts |
|
![]() Example my coding for Online Form,,,,what matter for my coding??anybody know?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Announcement Sent</title> <meta content="php, contact, form, thinking" name="keywords"> <meta content="Great success!" name="description"> <style type="text/css"> div.divmain { background:url(BG/ARF-BG1.png) center no-repeat; width: 75%; padding-top: 25%; padding-bottom: 35%; } input.test{ color:#CCCCCC; background-color:#333333; font-family: Bauhaus 93; font-size: 14pt; text-decoration : bold; } a:link, a:active, a:visited { color : "#009999"; text-decoration: none; background: "#003366"; font-family: Bauhaus 93; font-size : 24; } a:hover { color : "#00CC99"; text-decoration: none; background : "#003366"; font-family: Bauhaus 93; font-size : 24; } body { background:url(BG.png) repeat fixed center; } .style22 { font-size: 16px; font-style: italic; } </style> </head> <body> <?php if(isset($_POST['submit'])) { $to = 'noor.syamimi@mediu.ws, noor.syamimi@mediu.edu.my, mimie_pooh@yahoo.com'; $subject = 'Announcement Form'; // define variables and set to empty values $name_field = $email_field = $department_field = $titleEnglish_field = $titleMalay_field = $titleArabic_field = $titleFrance_field = $contentEnglish_field = $contentMalay_field = $contentArabic_field = $contentFrance_field = $datePubEng_field = $datePubMal_field = $datePubAr_field = $datePubFr_field = $dateExpEng_field = $dateExpMal_field = $dateExpAr_field = $dateExpFr_field = ""; // data the visitor provided $name_field = filter_var($_POST['request_by'], FILTER_SANITIZE_STRING); $email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL); $department_field = filter_var($_POST['department'], FILTER_SANITIZE_STRING); $titleEnglish_field = filter_var($_POST['Title(ENGLISH)'], FILTER_SANITIZE_STRING); $contentEnglish_field = filter_var($_POST['Content(ENGLISH)'], FILTER_SANITIZE_STRING); $datePubEng_field = filter_var($_POST['SelectedDateEngPub'], FILTER_SANITIZE_STRING); $dateExpEng_field = filter_var($_POST['SelectedDateEngExp'], FILTER_SANITIZE_STRING); //$auditedEng_field = filter_var($_POST['auditedEng'], FILTER_VALIDATE_BOOLEAN); $titleMalay_field = filter_var($_POST['Title(MALAY)'], FILTER_SANITIZE_STRING); $contentMalay_field = filter_var($_POST['Content(MALAY)'], FILTER_SANITIZE_STRING); $datePubMal_field = filter_var($_POST['SelectedDateMalPub'], FILTER_SANITIZE_STRING); $dateExpMal_field = filter_var($_POST['SelectedDateMalExp'], FILTER_SANITIZE_STRING); //$auditedMal_field = filter_var($_POST['auditedMal'], FILTER_VALIDATE_BOOLEAN); $titleArab_field = filter_var($_POST['Title(ARABIC)'], FILTER_SANITIZE_STRING); $contentArab_field = filter_var($_POST['Content(ARABIC)'], FILTER_SANITIZE_STRING); $datePubAr_field = filter_var($_POST['SelectedDateArPub'], FILTER_SANITIZE_STRING); $dateExpAr_field = filter_var($_POST['SelectedDateArExp'], FILTER_SANITIZE_STRING); //$auditedAr_field = filter_var($_POST['auditedAr'], FILTER_VALIDATE_BOOLEAN); $titleFrance_field = filter_var($_POST['Title(FRANCE)'], FILTER_SANITIZE_STRING); $contentFrance_field = filter_var($_POST['Content(FRANCE)'], FILTER_SANITIZE_STRING); $datePubFr_field = filter_var($_POST['SelectedDateFrPub'], FILTER_SANITIZE_STRING); $dateExpFr_field = filter_var($_POST['SelectedDateFrExp'], FILTER_SANITIZE_STRING); //$auditedFr_field = filter_var($_POST['auditedFr'], FILTER_VALIDATE_BOOLEAN); //constructing the message $message = "<html> <head> <title>Title of email</title> </head> <body> <table border=\"1px\" align=\"center\"> <tr> <td><b>From:</b> $name_field</td> <td><b>E-Mail:</b> $email_field</td> <td><b>Department:</b> $department_field</td> </tr> </table> <table border=\"1px\" align=\"center\"> <tr> <td></td> <td><b>English</b></td> <td><b>Malay</b></td> <td><b>Arabic</b></td> <td><b>France</b></td> </tr> <tr> <td><b>Title:</b></td> <td>$titleEnglish_field</td> <td>$titleMalay_field</td> <td>$titleArab_field</td> <td>$titleFrance_field</td> </tr> <tr> <td><b>Announcement:</b></td> <td>$contentEnglish_field</td> <td>$contentMalay_field</td> <td>$contentArab_field</td> <td>$contentFrance_field</td> </tr> <tr> <td><b>Date Published:</b></td> <td>$datePubEng_field</td> <td>$datePubMal_field</td> <td>$datePubAr_field</td> <td>$datePubFr_field</td> </tr> <tr> <td><b>Date Expired:</b></td> <td>$dateExpEng_field</td> <td>$dateExpMal_field</td> <td>$dateExpAr_field</td> <td>$dateExpFr_field</td> </tr> </table> </body> </html>"; function authgMail($from, $namefrom, $to, $nameto, $subject, $headers, $message) { $smtpServer = "192.168.xxx.xxx"; //ip address of the mail server. This can also be the local domain name $port = "25"; // should be 25 by default, but needs to be whichever port the mail server will be using for smtp $timeout = "45"; // typical timeout. try 45 for slow servers $username = "syamimi"; // the login for your smtp $password = "syamimi2013"; // the password for your smtp $localhost = "172.17.250.175"; // Defined for the web server. Since this is where we are gathering the details for the email $newLine = "\r\n"; // aka, carrage return line feed. var just for newlines in MS $secure = 0; // change to 1 if your server is running under SSL //connect to the host and port $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout); $smtpResponse = fgets($smtpConnect, 4096); if(empty($smtpConnect)) { $output = "Failed to connect: $smtpResponse"; echo $output; return $output; } else { $logArray['connection'] = "<p>Connected to: $smtpResponse"; echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />"; } //you have to say HELO again after TLS is started fputs($smtpConnect, "HELO $localhost". $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['heloresponse2'] = "$smtpResponse"; //request for auth login fputs($smtpConnect,"AUTH LOGIN" . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['authrequest'] = "$smtpResponse"; //send the username fputs($smtpConnect, base64_encode($username) . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['authusername'] = "$smtpResponse"; //send the password fputs($smtpConnect, base64_encode($password) . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['authpassword'] = "$smtpResponse"; //email from fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['mailfromresponse'] = "$smtpResponse"; //email to fputs($smtpConnect, "RCPT TO: <$to>" . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['mailtoresponse'] = "$smtpResponse"; //the email fputs($smtpConnect, "DATA" . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $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; //observe the . after the newline, it signals the end of message fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n"); $smtpResponse = fgets($smtpConnect, 4096); $logArray['data2response'] = "$smtpResponse"; // say goodbye fputs($smtpConnect,"QUIT" . $newLine); $smtpResponse = fgets($smtpConnect, 4096); $logArray['quitresponse'] = "$smtpResponse"; $logArray['quitcode'] = substr($smtpResponse,0,3); fclose($smtpConnect); //a return value of 221 in $retVal["quitcode"] is a success return($logArray); } $err=0; // so far, so good $err_msg=""; if($_POST['name_field']!="") { echo $_POST['name_field']."<br>"; } else { $err=1; $err_msg="You must include your name";} // Check for the existence of an AT symbol inside the email. if (strpos($_POST['email_field'],"@")) { echo $_POST['email_field']."<br>"; } else { $err=1; $err_msg="You must include a current email address."; } echo $err_msg; if($err<=0) { $from="noor.syamimi@mediu.ws"; $namefrom="Mediu"; $to = "noor.syamimi@mediu.edu.my"; $nameto = "WPU"; $subject = "MEDIU ANNOUNCEMENT"; $message = "Email from My Domain"; // this is it, lets send that email! authgMail($from, $namefrom, $to, $nameto, $subject, $headers, $message) } else { echo "<p /> This form was not filled out correctly, please correct any mistakes."; } ?> <center> <div class="divmain"> </div> </center> </body> </html> |
info at phpclasses dot org
.