January 23, 201016 yr Hi, I'm trying an old tutorial from a magazine and had problems getting it to work. I've downloaded the source tutorial files and pasted them into my page (at the top before anything else). When I click submit it throws up this error: Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\testsite\pages\contact.php on line 22 Heres the PHP.. <?php if(isset($_POST['Submit'])) { $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; $mailing = $_POST['mailing']; if($name == '' or $email == '' or $comments == '') { $err = true; $msg = 'Please complete your name, email address and comments to submit the form.'; } else { $mailmsg = 'The following email has been sent from the contact form:' . "\n\n"; $mailmsg.= 'Name: ' . $name . "\n"; $mailmsg.= 'Email: ' . $email . "\n"; $mailmsg.= 'Comments: ' . $comments . "\n"; if($mailing == 'true') { $mailmsg.= 'I would like to be added to the mailing list'; } if (eregi("\r",$email) || eregi("\n",$email)){ die ("spam!"); } else { if(mail('myvalid@email.com','Contact Form', $mailmsg, "From: noreply@example.com")) { header("Location: thankyou.html"); } } } } ?> I've tried uploading to my webspace but it won't even open the page, it just tried to open in DW!! I could imagine it being a typo if I'd have typed it out but this is a copy n paste from the original file! Thanks...Andre
January 23, 201016 yr Download PHPmailer. http://phpmailer.worxware.com/index.php?pg=sf&p=dl then use it like this: // include the lib include ('phpmailer/class.phpmailer.php'); // init $mail = new PHPMailer; // SMTP INFO $mail->Host = 'smtp.yoursite.com'; $mail->Mailer = 'smtp'; $mail->Password = 'password123'; $mail->Username = 'no-reply@yoursite.com'; $mail->SMTPAuth = TRUE; // Email $mail->From = 'no-reply@yoursite.com'; $mail->FromName = 'Yoursite.com'; $mail->Subject = 'A HTML EMAIL!'; $mail->Body = '<p>this is an example of a HTML email!'; // Html email? $mail->IsHTML(TRUE); // Send to $mail->addAddress('person@site.com'); $mail->addAddress('person2@site.com'); $mail->addAddress('person3@site.com'); // Send email. if(!$mail->Send()) { echo 'Email could not be sent.'; } else { echo 'Email was sent!'; }
January 24, 201016 yr Try sending a simple email with mail() first (Go to the PHP website and get an example) to make sure that you have a operational mail server.
Create an account or sign in to comment