January 1, 201016 yr Hello, I've begun to learn the basics of PHP and have been trying to create a simple contact form. I'm using XAMPP for Apache etc. I've configured php.ini to what i think is correct: [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = *****.*****.co.uk ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = ***@********.co.uk ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" I've taken the script from an online tutorial on how to create a simple contact form. The PHP is as follows: <?php $email = $_GET['email'] ; $message = $_GET['message'] ; mail( "***@********.co.uk", "Email Subject", $message, "From: $email" ); ?> Every time i try to use the form to test it i get the same error coming up: Warning: mail() [function.mail]: SMTP server response: 553 This SMTP server requires authorisation. Most mail clients can be configured with "my server requires authorisation" to allow this in C:\xampp\htdocs\sendmail.php on line 4 I'm using MS Outlook 2003 as my mail client. I've tried so many different things to try and sort it but have got nowhere. Can anybody offer any advice. Thanks
January 1, 201016 yr For a start i wouldn't use the "get" method when using forms, always use "post". The "get" method sends data in a very exposed way by including it inside the browser bar(URI). And it looks like you have something missing from the mail function? I have included the code for a contacts form that i always use... HTML: <form id="feedback" method="post" action=""> <p> <label for="name">Name:</lable> <input name="name" id="name" type="text" class="formbox" /> </p> <p> <label for="email">Email:</lable> <input name="email" id="email" type="text" class="formbox" /> </p> <p> <label for="comments">Comments:</lable> <textarea name="comments" id="comments" cols="50" rows="8"></textarea> </p> <p> <input name="send" id="send" type="submit" value="send message" /> </p> </form> PHP: <?php // Process the email using an if statement(conditional) if(array_key_exists('send', $_POST)){ &to = 'yourmemail@mail.com'; // Use your own email address here &subject = 'Enquiry from web site'; // Process the $_POST variables $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; // Build the email message $message = "Name: $name "; $message .= "Email: $email "; $message .= "Comments: $comments "; // Send it using the mail() function and store the value inside the $mailSent variable $mailSent = mail($to, $subject, $message); } ?> This is the very bare bones of a web form and there is other ways of doing forms but this is how i was taught. You can add loads more if desired such as redirect the user to another page by using the $mailSent variable. Let me know if you have any problems with it or you want to add a bit more to it?
January 1, 201016 yr Your error message tells you that your server needs authorization. So you have to put an username and a passwort into the mix. Heres how it works: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
January 2, 201016 yr Author Thanks for your comments. As mentioned before the script is just very basic and is something i've found off the net to test with. I will have a look at your code and see how it works. Thanks for the link. I'm going to have a look through and see if i finally get there.
January 2, 201016 yr Author Hi Neilp. I've had a go at using the script you sent me and it's coming up with an error saying 'Unexpected '&'on the follwing line: &to = 'yourmemail@mail.com'; // Use your own email address here I've put in the email address i would like it sending to. Am i supposed to change anything else? Thanks
January 3, 201016 yr Author Hi Rallport, As mentioned i'm a complete beginner to php and am just learning the basics now. For now my problem is setting up my computer to be able to send test emails from a contact page hosted on my computer using xampp. Still struggling with it now. I used the script you mentioned as i was suggested to me and as i have no php experience i've gone with it. i initially used a much simpler script purely for testing purposes (setting up the sendmail i should say) TopShopper, Thanks for that. It's sorted things out with that error now.
Create an account or sign in to comment