Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Contact form error...

Featured Replies

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

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!';
}

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.