Jump to content

Initiate Php Mail


mwbarry

Recommended Posts

I am trying to make a contact form that will be emailed to the site owner. How do I initiate the php mail script when a link is clicked? As of now the mail is sent when the page is loaded and when i click the send link there is an error that mail() is undefined, but how do I call the script onclick? html

 <div id="contactboxinfo">	  <input type="text" name="first name" value="First Name" class="box" />	  <input type="text" name="last name" value="Last Name" class="box" />	  <br />	  <input type="text" name="email address" value="Email Address" class="box" />	  <input type="text" name="phone number" value="Phone Number" class="box" />	  <br />      <a href="#" onclick="mail()"><img src="sendbutton.png" alt="sendbutton" /></a></div>

php

<?php $to = "owner@gmail.com";$subject = "test mail";$txt = "did it work?";$headers = "From: me@localhost.com";mail($to,$subject,$txt,$headers);?>

secondly, how would I go about calling the inputs into the message body?

Link to comment
Share on other sites

PHP is not Javascript. It runs before the page loads and then stops running. You should have a special PHP file that sends mail, and to prevent it from sending automatically when the page opens, check that a POST value was passed from a form.Check the W3Schools PHP tutorial and learn some PHP first, then look up how to send mail

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...