PHP - Php Contact Form Sending To Email Via Smtp Authentication
Hi
I am very new to PHP. I'm wanting a feedback form on my website where the form is sent via SMTP rather than sendmail. I have checked that php is working by doing this code: Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', True); $path = '/home/****/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); echo("<p>Sending PEAR Mail.php...</p>"); require('Mail.php'); $from = "Info <info@***.co.uk>"; $to = "Info <info@***.co.uk>"; $subject = "Hi - Test message!"; $body = "Hi,\n\nHow are you?"; $host = "mail.***.co.uk"; $username = "info@***.co.uk"; $password = "***"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> This works fine. I then created a form in my contact page: Code: [Select] <form name="feedbackform" action="form-mailer2.php" method="post"> <input type="hidden" name="Required" value="Name,Comments"> <p>Name: <input name="Name" size="30"> <span class="formsmall">required</span></p> <p>E-mail: <input name="Email" size="30"> <span class="formsmall">optional</span></p> <p>Feedback/Comments:</p> <p><textarea name="Comments" rows="5" cols="40"></textarea></p> <p><input type="submit" value="Submit" name="submitform"><input type="reset" value="Reset" name="reset"></p> </form> I then used the code based on the php initial example and the code file that would get the form details from the contact page and send to the email address via smtp. I have left the validations in - although if these are no good please feel free to tell me! I will want to put a captcha in but need to look into that yet. Anyway, the code I have created is now this (which is saved in the file form-mailer2.php): Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', True); $path = '/home/****/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); echo("<p>Sending PEAR Mail.php...</p>"); require('Mail.php'); $mailfrom = "info@***.co.uk"; $mailTo = "info@***.co.uk"; $mailSubject = "Web Feedback"; $mailHost = "mail.***.co.uk"; $mailPort = "25"; $mailAuth = "true"; $mailPassword = "****"; // Get the form fields. $name = $_POST['Name']; $email = $_POST['Email']; $comments = $_POST['Comments']; $reqFields = $_POST['Required']; // I find including the time/date useful for record-keeping. // Note that it is the web server's time/date, not yours // or the sender's. $date = date("l jS F Y, g:i A"); // A simple yet reasonably effective email address validator. if ((!ereg(".+\@.+\..+", $email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $email))) { $errorMessages .= "<li>Invalid email address: $email</li>"; } // Make sure required fields are filled in. $checkFields = explode(",",$reqFields); while(list($theField) = each($checkFields)) { if(!$$checkFields[$theField]) { $errorMessages .= "<li>Missing $checkFields[$theField]</li>"; } } // If there are errors, display them and a back button. if($errorMessages) { ?> <p>Errors were found on the form.</p> <ul> <?php echo $errorMessages; ?> </ul> <p><input type="button" value="Back" onClick="history.back()"></p> <?php } // No errors, send the message and print out success message. else { // Build the email. $body = " Name: $Name Email: $Email Phone: $Phone ----- Comments ----- $Comments -------------------- $headers["From"] = $mailTo; $headers["To"] = $mailTo; $headers["Subject"] = $mailSubject; $params["host"] = $mailHost; $params["port"] = $mailPort; $params["auth"] = $mailAuth; $params["username"] = $mailTo; $params["password"] = $mailPassword; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($mailTo, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } // I would rather redirect to a different thank you page but both of next options don't work when taking out: echo("<p>Message successfully sent!</p>"); //RedirectToURL("thank-you.php"); or header(Location: "thank-you.php" ); ?> Depending on what I change about I either get: The website cannot display the page or a list of undefinable variables. If anyone is able to understand the php and notice where the problem lies I would be so grateful. Thank you. Similar TutorialsHi I really would appreciate if some phpfreak can help me with this please . I need to my contact page send emails so that when recipient receives it, it comes with the correct domain (same as the web address) it is coming from rather than the server name. At the moment they are coming as abcd20@elessar.nocdirect.com and would like them come as abcd20@myowndomain.com (lets say my password for that email is 'zzzaaa' and the domain was myowndomain.com ) Here is my email contact php script which works fine and hopefully would not have to change too much. My Contact form is posting to 'send.php' . On top of my contacts page there is a js script for 'jquery.js' and some jQuery stuff for validation.. Have seen many scripts but could not adapt to my existing send.php script. Can you please help? ------ Content of 'send.php' ----------------------------------- <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','phone','message'); $required = array('name','email','phone','message'); $your_email = "abcd20@myowndomain.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "New message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> -------------------------------------------------------------------------------- Hello, I'm new to PHP but i am quite good with javascript programming etc so i'm just getting to terms with using PHP. I've made a contact form with an IF statement that will display confirmation within my page upon post. (I'm not even sure if this logic is right however). The form seems to submit but doesn't show the confirmation message and doesn't send an email to my webserver. Code: [Select] <body> <div id="outer"> <div id="topbar"> </div> <div id="topback"> <img src="images/logo.png" class="logo" /> <a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('hemcurrent','','images/homecurrent.png',1)"><img src="images/home.png" class="logo hem" name="hemcurrent" /></a> <a href="Tjanster.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('tjanstercurrent','','images/tjanstercurrent.png',1)"><img src="images/tjanster.png" class="logo links" name="tjanstercurrent" /></a> <a href="OmOss.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('omosscurrent','','images/omosscurrent.png',1)"><img src="images/omoss.png" class="logo links" name="omosscurrent" /></a> <a href="Referenser.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('referensercurrent','','images/referensercurrent.png',1)"><img src="images/referenser.png" class="logo links" name="referensercurrent" /></a> <a href="KontaktaOss.html"><img src="images/kontaktaosscurrent.png" class="logo links" /></a> </div> <div id="maincontent"> <h1>Nordströms HRK AB - </h1> <h2 class="kontaktaoss"> KONTAKTA OSS</h2> <?php if ($_POST["email"]<>'') { $ToEmail = 'michel@hissorulltrappskonsulter.se'; $EmailSubject = 'Webform Hissorulltrapp'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"].""; $MESSAGE_BODY .= "Email: ".$_POST["email"].""; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> Your message has been sent <?php } else { ?> <form name="form" id="form" action="KontaktaOss.php" method="post"> <select name="sDepartment" onchange="MM_jumpMenu('parent',this,0)" class="selectDepartment"> <option>Hiss och rulltrappstjänster</option> <option>Teknisk support</option> </select> <input type="text" name="subject" id="name" class="txtDepartment" /> <textarea name="tComments" id="comment" class="txtComments"></textarea> <input type="text" name="tEmail" id="email" class="txtEmail" /> <input type="image" src="images/submit.png" class="bSubmit" value="send" /> <input type="image" src="images/reset.png" class="bReset" /> </form> <?php }; ?> <p class="kontaktaossdetails"><b>Information:</b><br /> Stationsvägen 4C<br /> Täby 187 30 <br /> Telefon: 0702698981<br /> bjorn@hissotrulltrappskonsulter.se<br /> michel@hissorulltrappskonsulter.se<br /> <b>Teknisk Support:</b><br /> joel@hissorulltrappskonsulter.se</p> </div> <div id="tagline"><img class="quote1" src="images/quote1.png" /> <div id="elem0" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem1" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem2" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem3" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem4" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem5" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem6" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem7" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem8" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem9" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem10" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem11" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <img class="quote2" src="images/rightquote.png" /> <img src="images/btnLogin.png" class="btnlogin" /> </div> <div id="copyright"> <ul id="nav"> <li>LANGUAGES: </li> <li><a href="#">ENGLISH</a></li> <li><a href="#">SWEDISH</a></li> <li><a href="#">HELP</a></li> <li>COPYRIGHT BY NORDSTRÖMS HRK AB</li> </ul> </div> <div id="mac"> <div id="macscreen"> <iframe width="336" height="216" src="http://www.youtube.com/embed/AhfK9_ZlRXQ?hl=en&fs=1&rel=0&autoplay=1&autohide=1&showinfo=0&controls=0&loop=1" frameborder="0"></iframe> </div> </div> </div> </body> Just looking for some advice really, i'm sure it's something very simple! Thank you. From our website we are connecting to GMAIL to send our emails through SMTP. For some reason it is not sending the emails to the CC or BCC email address event though GMAIL shows it was included in the email. Am I missing something in the below code? Code: [Select] $currentTime = time(); $emailTo = "redbrad0@domain.com"; $emailCC = "brad@domain.com"; $emailBCC = "events@domain.com"; $emailSubject = "TEST Email at (" . $currentTime . ")"; $emailBody = "This is the body of the email"; $headers = array(); if (!empty($emailTo)) $headers['TO'] = $emailTo; if (!empty($emailCC)) $headers['CC'] = $emailCC; if (!empty($emailBCC)) $headers['BCC'] = $emailBCC; if (!empty($emailSubject)) $headers['Subject'] = $emailSubject; $headers['From'] = "events@domain.com"; $mime = new Mail_mime("\n"); $mime->setTXTBody($emailBody); $body = $mime->get(); $headers = $mime->headers($headers); $mail = Mail::factory('smtp', array ('host' => 'ssl://smtp.gmail.com', 'auth' => true, 'port' => 465, 'username' => 'events@domain.com', 'password' => 'thepasswordhere')); try { $result = $mail->send($emailTo, $headers, $emailBody); } catch (TixException $ex) { echo "<font color=red>Error:" . $ex->getCode() . "</font><br>"; } echo "Emailed at (" . $currentTime . ")<br>"; die; I really need some help. I am very new to PHP and I've been stuck for a couple of days. I created a contact form and everything seems to be working correctly, except the mail is showing it's sent, but I never receive an email in my Inbox or Spam folder. Can someone please review my code? Here is the PHP: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varpositionErr = ""; $varfname = $varlname = $varemail = $varphone = $varposition = $success = ""; //FORM SUBMITTED WITH POST METHOD if ($_SERVER["REQUEST_METHOD"] == "POST") { //VALIDATE FIRST NAME if (empty($_POST["varfname"])) { $varfnameErr = "First Name is required"; } else { $varfname = test_input($_POST["varfname"]); // MAKE SURE FIRST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varfname)) { $varfnameErr = "Only letters and white space are allowed"; } } //VALIDATE LAST NAME if (empty($_POST["varlname"])) { $varlnameErr = "Last Name is required"; } else { $varlname = test_input($_POST["varlname"]); // MAKE SURE LAST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varlname)) { $varlnameErr = "Only letters and white space are allowed"; } } //VALIDATE EMAIL ADDRESS if (empty($_POST["varemail"])) { $varemailErr = "Email Address is required"; } else { $varemail = test_input($_POST["varemail"]); // MAKE SURE EMAIL ADDRESS IS FORMATTED CORRECTLY if (!filter_var($varemail, FILTER_VALIDATE_EMAIL)) { $varemailErr = "Invalid email address format"; } } //VALIDATE PHONE NUMBER if (empty($_POST["varphone"])) { $varphoneErr = "Phone number is required"; } else { $varphone = test_input($_POST["varphone"]); // MAKE SURE PHONE NUMBER IS IN CORRECT FORMAT if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$varphone)) { $varphoneErr = "Invalid telephone format"; } } //VALIDATE POSITION if (empty($_POST["varposition"])) { $varpositionErr = "Position is required"; } else { $varposition = test_input($_POST["varposition"]); } //IF ALL DATA IS CORRECT if ($varfnameErr == '' and $varlnameErr == '' and $varemailErr == '' and $varphoneErr == '' and $varpositionErr == '') { $message_body = ''; unset($_POST['submit']); //THIS IS JUST FOR TESTING PURPOSES $message_body = $varfname; //foreach ($_POST as $key => $value) { // $message_body .= "$key: $value\n"; //} $to = 'mygmail@gmail.com'; $subject = 'Volunteer Form Submission'; $message = wordwrap($message_body, 70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . $varemail . "\r\n"; $subject = 'Volunteer Form Submission'; $to = 'mygmail@gmail.com'; $result = mail($to, $subject, $message, $headers); //THIS RETURNS "1" print $result; //IF ALL DATA IS CORRECT MAKE SURE EMAIL WAS SENT if (mail($to, $subject, $message, $headers)) { $success = "Message sent. Thank you contacting us! We will reply as soon as possible."; $varfname = $varlname = $varemail = $varphone = $varposition = ""; } else { $success = "Something went wrong!"; } } } //STRIP UNWANTED CHARACTERS FROM VARIABLES function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
Here is the HTML: <div class="row regformrow"> <div class="coffee-span-12 regformcolumn"> <div class="subgrid regformsubgrid"> <div class="row regformsubgridheaderrow"> <div class="coffee-span-12 regformsubgridheadercolumn"> <h4 class="regformsubgridheadertitle">Volunteer Form</h4> </div> </div> <div class="row regformsubgridrow"> <form class="form-container regformsubgridformcontainer" action=<?= $_SERVER['PHP_SELF']; ?> method="post"> <div class="coffee-span-4 coffee-972-span-6 coffee-458-span-12 regformsubgridcolumn1"> <div class="container regformsubgridcontainer1"> <label class="label form-label-all"><span style="font-style:italic;color:#FF5454;">* Required Fields</span></label></br> <div class="formfieldgroup"> <input class="fname" name="varfname" type="text" tabindex="1" placeholder="First Name" value="<?= $varfname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varfnameErr ?></span> </div> <div class="formfieldgroup"> <input class="lname" name="varlname" type="text" tabindex="2" placeholder="Last Name" value="<?= $varlname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varlnameErr ?></span> </div> <div class="formfieldgroup"> <input class="email" name="varemail" type="text" tabindex="2" placeholder="Email Address" value="<?= $varemail; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varemailErr ?></span> </div> <div class="formfieldgroup"> <input class="phone" name="varphone" type="text" tabindex="2" placeholder="Telephone Number" value="<?= $varphone; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varphoneErr ?></span> </div> <div class="formfieldgroup"> <select class="select selectbox" name="varposition" id="varposition" tabindex="5"><option value="">Select one...</option><option value="Chaperone">Chaperone</option><option value="Class Monitor">Class Monitor</option><option value="Parking Attendant">Parking Attendant</option><option value="Party Coordinator">Party Coordinator</option><option value="Teacher Aid">Teacher Aid</option></select><span class="requiredfield"> *</span> <span class="form-error"><?= $varpositionErr ?></span> </div> <div class="formfieldgroup"> <input class="test" name="test" type="text" tabindex="6" placeholder="If you are human, leave this field blank" value=""> </div> <div class="formfieldgroup"> <button type="submit" class="button-submit-1" name="submit" tabindex="7" data-submit="...Sendng">Submit</button> </div> <div class="formfieldgroup"> <div class="success"><?= $success; ?></div> </div> </div> </div> </form> </div> </div> </div> </div> Edited February 20, 2020 by mike3075 How to add SMTP authentication for PHP mail form which is using POST function... Is this true, i have cookies on my site till i send a form which fires off two emails. the cookies are not only deleted, but i can reset the cookie to the proper values unless i delete all my cookies!! any ideas? $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.gmail.com', 'smtp_port' => '465', 'smtp_user' => 'removed@removed.nothing', 'smtp_pass' => 'removed' ); but I can't send that email... It show error like this... A PHP Error was encountered Severity: Warning Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) Filename: libraries/Email.php Line Number: 1673 A PHP Error was encountered Severity: Warning Message: fwrite(): supplied argument is not a valid stream resource Filename: libraries/Email.php Line Number: 1816 Hi everyone, this is my first post. i am starting to learn flash and other programs and haven't started on PHP yet. I have purchased a template that i am modifying and the problem i am having is that my server is a windows one and doesn't like the code that i have attached. It is very simple and doesn't offer any protection with strip slashes etc but the real problem is that i need to add the smpt auth. I have tried several lines of code but it doesnt seem to work. I cant change the headers so i am hoping i can get a little help from this community. It is greatly appreciated Hi I have a simply working SMTP form, however I need this to send to a yahoo.com email address, what can I add to achieve this? SmtpConfig.php ============== <?php //Server Address $SmtpServer="91.186.30.25"; $SmtpPort="25"; //default $SmtpUser="things@wilsoncarandvanrental.co.uk"; $SmtpPass="things123"; ?> SmtpClass.php ============= <?php class SMTPClient { // A function for Setting up SMTP function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body) { $this->SmtpServer = $SmtpServer; $this->SmtpUser = base64_encode ($SmtpUser); $this->SmtpPass = base64_encode ($SmtpPass); $this->from = $from; $this->to = $to; $this->subject = $subject; $this->body = $body; //Setting Default port Value if ($SmtpPort == "") { $this->PortSMTP = 25; } else { $this->PortSMTP = $SmtpPort; } } //Sending the Mail function SendMail () { if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) { fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n"); $talk["hello"] = fgets ( $SMTPIN, 1024 ); fputs($SMTPIN, "auth login\r\n"); $talk["res"]=fgets($SMTPIN,1024); fputs($SMTPIN, $this->SmtpUser."\r\n"); $talk["user"]=fgets($SMTPIN,1024); fputs($SMTPIN, $this->SmtpPass."\r\n"); $talk["pass"]=fgets($SMTPIN,256); fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n"); $talk["From"] = fgets ( $SMTPIN, 1024 ); fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n"); $talk["To"] = fgets ($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"]=fgets( $SMTPIN,1024 ); fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n"); $talk["send"]=fgets($SMTPIN,256); //CLOSE CONNECTION AND EXIT ... fputs ($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); // } return $talk; } } ?> mail.php ======== <?php //Include Class And Config include('SmtpConfig.php'); include('SmtpClass.php'); //Check the Request Method if($_SERVER["REQUEST_METHOD"] == "POST") { $to = $_POST['to']; $from = $_POST['from']; $subject = $_POST['sub']; $body = $_POST['message']; // Send the mail Using the class $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body); $SMTPChat = $SMTPMail->SendMail(); } // After Exit, show the form ?> <form method="post" action=""> To:<input type="text" name="to" /> From :<input type='text' name="from" /> Subject :<input type='text' name="sub" /> Message :<textarea name="message"></textarea> <input type="submit" value=" Send " /> </form> Probably quite straight form, but of course I don#t know how :0) Much appreciated. Please help: I'm trying to figure out what is going on with a custom made PHP contact form on my company's multiple websites. Check it out he www.TacticalSolar.com This custom form was made by a former employee and USUALLY works great. Validation, spam checking, database connection, etc. But I've discovered a bug. The form does not always actually send the data to us when it says it does! This problem almost always happens in Internet Explorer and Safari browsers. But sometimes that data shows up. This does not effect Firefox or Chrome. I've been looking everywhere, but no idea what is causing this. Thoughts? Ideas? I'm no PHP coder so even obvious places to look are welcome. Hi- I am new to php, trying to make a simple form that emails when submitted. It works fine on my own server, but when I try it on my work server I get: Warning: mail() [function.mail]: SMTP server response: 550 Authentication is required for relay in C:\inetpub\wwwroot\OMC\estimate3.php on line 159 here are the headers: $headers = "From: info@combatstocks.com\n"; $headers .= "X-Mailer: PHP4\n"; $headers .= "X-Priority: 3\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"==MIME_BOUNDRY_alt_main_message\"\n\n"; and the mail() function mail($to,$subject,$body,$headers); let me know if you need more code and ill happily supply it. thanks! Basically what I am needing is when a visitor comes to my site and request info on a product, the form sends the product id or name.
I have the site set up like product.php?Item=26 and the item number changes based on the product. The page items are being populated with info stored in the mysql databse.
I need the email being sent to say something like
Visitors Name has requested info on Item 26 Name - Visitors Name Email - email@me.com Phone - 123-456-7890 Company - Visitors Company Item info requested for Here is the products name URL to product page Basically the "item info" is being pulled from the database. I have asked on different forums and I cannot get a good answer that I can use to make this happen. I might not be explaining it right. Page the form is on is (and all other new-product.php pages) http://www.packagingequipment4sale.com/new-product.php?Item=26Any help would be greatly appreciated Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: I've been ALL over the internet trying to find complete step by step guides on getting php to work for my contact form and I can't find anything. Or at least nothing that makes sense to me. I know nothing about PHP, I'm more of a designer/html/css person. PHP is completely foreign to me and very hard to understand. I have downloaded PHPMailer but I have no idea what I'm supposed to do with it or how to really configure it. I really need help in that area. This contact form is the last thing I need before I can put my redesign of my website up.
Hi the user fill details and then the email his sent to me the only problem is that the emails keeps going to my spam, can someone help me out please I looked already php website and email format looks the same. This is the link to my form. http://www.people.eurico.co.uk/ here my form script Code: [Select] <?php // Set email variables $email_to = 'xxxxx@xxxxxxx.co.uk'; $email_subject = 'Call back form'; // Set required fields $required_fields = array('fullname','email','telephone','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'email' => 'Please enter a valid Email.', 'telephone' => 'Please telephone.', 'comment' => 'Please enter your Message to continue.' ); // Set form status $form_complete = FALSE; // configure validation array $validation = array(); // check form submittal if(!empty($_POST)) { // Sanitise POST array foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value)); // Loop into required fields and make sure they match our needs foreach($required_fields as $field) { // the field has been submitted? if(!array_key_exists($field, $_POST)) array_push($validation, $field); // check there is information in the field? if($_POST[$field] == '') array_push($validation, $field); // validate the email address supplied if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // Prepare our content string $email_content = 'peoplesmartlearning.co.uk: ' . "\n\n"; // simple email content foreach($_POST as $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok then send the email mail($email_to, $email_subject, $email_content); // Update form switch $form_complete = TRUE; } } function validate_email_address($email = FALSE) { return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE; } function remove_email_injection($field = FALSE) { return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field)); } ?> The HTML Code: [Select] <div class="call_us_form"> <p class="title">WE'LL CALL YOU BACK</p> <?php if($form_complete === FALSE): ?> <form class="contact_form" id="fm-form" method="post" action="index.php" > <fieldset> <div class="fm-req"> <label for="fm-firstname">Name</label> <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /> <?php if(in_array('fullname', $validation)): ?><script type="text/javascript">alert("Please enter a Name"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Email</label> <input type="text" id="email" class="detail" name="email" value=" <?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /> <?php if(in_array('email', $validation)): ?><script type="text/javascript">alert("Please enter a valid Email Address"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Number</label> <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_POST['telephone'])? $_POST['telephone'] : ''; ?>" /> <?php if(in_array('telephone', $validation)): ?><script type="text/javascript">alert("Please enter telephone number"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-lastname">Message</label> <textarea cols="40" rows="5" id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea> <?php if(in_array('comment', $validation)): ?><script type="text/javascript">alert("Please enter your message"); history.back();</script><?php endif; ?> </div> <input class="submit_button" type="submit" value="Call us" /> </fieldset> </form> <?php else: ?> <p>Thank you for your Message!</p> <p>We will get back to you as soon as we can</p> <script type="text/javascript"> setTimeout ('ourRedirect()', 5000) function ourRedirect () { location.href='index.php' } </script> <?php endif; ?> As my titel indicates, I have a problem with a piece of code I wrote some time ago. Everything in my mail form is fine and the mails do get send. But they don't always arrive (checked spam folder). Hotmail or example arrives but a normal email adres from a provider does not. Could this have something to do with SMTP ? could I add this to my code ? I tryed some but so far it does not work, In the code below you can see my working code as it is & the tests I tryed and didn't work out that well. Code: [Select] <?php $fromemail="No-Reply <ikwerkthuis.be>"; // change here if you want $toemail=$naarwie; // change here if you want $sub="Online info aanvraag"; // change here if you want $success_page_name="bedankt.html"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3'])); $fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4'])); $fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5'])); $fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6'])); $fieldnm_7=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_7'])); $contentmsg=stripslashes('<br><b><font style=color:#CC3300>'. $sub .'</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_1 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_2 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_3 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_4 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_5 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_6 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Regio *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_7 .'</td> </tr> </table><br> Contactpersoon: '. $naarwie .'<br> IP: '. $IP .'<br> Date: '. $DATE .'<br> Time: '. $TIME .' '); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; @mail($toemail,$sub,$contentmsg,$headers);?> The code below is the code I tryed to apply to the code above that work. Code: [Select] <?php $fromemail="No-Reply <noreply@ikwerkthuis.be>"; // change here if you want $toemail=$naarwie; // change here if you want $sub="Online info aanvraag"; // change here if you want $success_page_name="bedankt.html"; $host = "ikwerkthuis.be"; $username = "noreply@ikwerkthuis.be"; $password = "hl2012"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3'])); $fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4'])); $fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5'])); $fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6'])); $fieldnm_7=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_7'])); $contentmsg=stripslashes('<br><b><font style=color:#CC3300>'. $sub .'</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_1 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_2 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_3 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_4 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_5 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_6 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Regio *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_7 .'</td> </tr> </table><br> Contactpersoon: '. $naarwie .'<br> IP: '. $IP .'<br> Date: '. $DATE .'<br> Time: '. $TIME .' '); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); @mail = $smtp->send($toemail,$sub,$contentmsg,$headers); ?> I hope someone can help me out. Thanks in advance ! Hi, I have a contact for which I wish to send to multiple recipients as a BCC, but I cannot work it out. I can add them as recipients, but they are not hidden in the email. This is what I have: if(isset($_POST['submit'])){ $name=$_POST['name']; $year=$_POST['year']; $email=$_POST['email']; $subject = 'Hello Admin !'; $message="Name : $name <br> Email : $email <br> Phone : $phone <br> Year : $year"; $recipients ="me@me.com, me2@me2.com"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject="New contact details"; $headers .= 'From: TEST<test@test.com>' . "\r\n"; mail($recipients ,$subject,$message,$headers); header("Location: thankyou.php"); Any ideas what I should do? Thanks Hi everyone.
Pretty desperate, first time that I'm working with php. Learning this language, makes sense, however I can't figure out why my code is not working.
Emails are not coming in at all. Additional required info (phone number, first name, last name) should be included in the message.
Please help. Thank you everyone.
<?php $to = "abcd@abcd.com"; $subject = "From Website Contact Form"; $first = $_REQUEST['first']; $last = $_REQUEST['last']; $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $MESSAGE_BODY = "Name: " . $_POST["first"] . "\n"; $MESSAGE_BODY = "Name: " . $_POST["last"] . "\n"; $MESSAGE_BODY = "Contact No: " . $_POST["phone"] . "\n"; $MESSAGE_BODY = "Email: " . $_POST["email"] . "\n"; $MESSAGE_BODY = "Requirement: " . nl2br($_POST["message"]) . "\n"; $message = $_REQUEST['message' + 'email' + 'first' + 'last']; $from = $_REQUEST['email']; $headers = "From:" . $from; mail($to, $subject, $MESSAGE_BODY, $headers); echo "Your message has been sent"; ?> I am trying to add my email to a contact form to where a customer would fill in a few boxes and hit send and i would receive. Where would i find the code to enter it? thanks, w Hi, I had a website running a few months ago with a working contact form I am now building a new website and have copied the files changing relevant info but it is not not working it is sending me to the thank you page but the email is not coming through. Can anybody see why? <?php $EmailTo = "MYEMAIL@gmail.com"; $Subject = "Contact from Website"; $Title = Trim(stripslashes($_POST['Title'])); $FName = Trim(stripslashes($_POST['First Name'])); $LName = Trim(stripslashes($_POST['Last Name'])); $Email = Trim(stripslashes($_POST['Email'])); // prepare email body text $Body = ""; $Body .= "Title: "; $Body .= $Title; $Body .= "\n"; $Body .= "First Name: "; $Body .= $FName; $Body .= "\n"; $Body .= "Last Name: "; $Body .= $LName; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$Email>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">"; } ?> Code: [Select] <form action="quoteform.php" method="post" enctype="multipart/form-data" name="quoteform" id="quoteform"> <label for="Title" id="Title">Title:</label><select name="Title"> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Dr">Dr</option> <option value="Other">Other</option> </select> <label for="FName" id="FName">First Name:</label><input name="First Name" type="text" size="25"> <label for="LName" id="LName">Last Name:</label><input name="Last Name" type="text" size="25"> <label for="Email" id="Email">Email:</label><input name="Email" type="text" size="50"> <input type="submit" name="submit" value="Send" class="submit-button" title="Submit" /> <input type="button" value="Clear Message" onClick="document.forms['quoteform'].Message.value=''" /> </form> |