Hi there, just after some extremely simple php code for a contact form that emails the details to an email address and then says "thank you etc" Cheers
It's actually quite simple if you have experience a little experience in php... You can create a simple contact form and then for the emailer, you can use this: http://www.w3schools.com/php/php_mail.asp
It is very simple to create contact form using PHP. Only few lines of codes is required. Some online tutorials are very helpful to guide stepwise to create contact form.
make a contact form in html using dreamweaver...and give proper naming to all input and create a submit button now you can follow the link www(dot)w3schools(dot)com/php/php_mail.asp ...if you need any help regarding coding then let us know.
Hi Kristenmorey111, I placed this on my contact.php page but I'm getting an error saying "failed to connect to smtp" etc, any ideas? <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("my@email.com", "$subject", $message, "From:" . $email); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='contact.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?>
Hi all, I uploaded it and it works fine online but no email is being sent? No error appears "your email has been sent" appears but it doesn't go into my inbox? No spelling mistakes or anything :/ I've 2 files, contact.php and sentcontact.php - any suggestions please? Thanks
Make sure that your email address is correct...I mean to whomever you wish to send is correct or not. mail("my@email.com", "$subject", $message, "From:" . $email); mail("proper_email_address@website.com", $subject,$message, "From:" . $email); hope it helps
One thing you need to be wary of is email header injection. With the script you have there I could bcc loads of other email addresses in and use your server your spam them. Look here for a simple example: www(dot)tonyspencer(dot)com/2005/12/15/email-injection-exploit-through-a-php-contact-form/ If you want a good solution with minimal coding effort look at some of the PHP mailer classes: sourceforge(dot)net/projects/phpmailer/ I don't want to discourage you from creating your own solution but just making you aware of the risks!
Are you sure your host supports PHP's mail() function? Try <?php error_reporting(E_ALL); $to = 'your.email@address.com'; if(mail($to, 'Testing mail', 'This is a mailing test to see if PHP mail works.')) { echo 'Mail was sent by PHP'; } else { echo 'PHP could not send the mail'; } ?> PHP: (Replace with your email address.) Run the page. (Save it as emailtest.php, for example, then go to http://www.yoursite.com/emailtest.php.) If you don't get the email, contact your hosting company.
Hi everyone, thank you for your replies. I only just got a chance to try the php code and it said "Mail was sent by PHP".... AND I got the email.... SO, The question remains, what is wrong with my original code please?
It could be "From:" . $email It should be "From: " . $email (There should be a space after the colon.) Also $email = $_REQUEST['email'] ; should be $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : ''; if(!$email) { //send the user an error and don't try to sent the email } PHP:
Hi Rukbat, thanks for the reply. Tried the "From:" . $email It should be "From: " . $email and that made no difference Couldn't find the other part to edit :/ I really just need something really, really simple - dunno why it won't work.
Without a dump of the full string being sent to the mail() function, it's all guesswork. If you could install Firebug and FirePHP, and learn to use them, and change mail("my@email.com", "$subject", $message, "From:" . $email); PHP: to $mail = "my@email.com,$subject,$message, From: $email"; fb::log($mail); mail($mail); PHP: then post the line FirePHP gives you, it would be easier to troubleshoot.
Hi WPC, I did try an alternative mail script earlier in this post and it did work but my script won't work - any suggestions please?
Try the following code: $to = 'email_addr@domain.com '; $subject = 'Your Subject'; $body = "\r\nYour Mail Body"; $mail_sent = mail($to, $subject, $body); echo $mail_sent ? "Mail sent" : "Mail failed"; PHP: It worked for me. It doesn't have "header" information by the way Cheers