Jump to content

sending php mail in a php function after a button click


agregoire

Recommended Posts

I am a new php user and am having troubles with my php mail function. 

 

My page is an employee hour submit page, it uses an html form to get the input, submits the form to itself and to an error checking function after pressing submit.  Then the page displays the information just entered and displays another button at the bottom of the page.

 

  The idea is that when they press the 2nd button the form information will then be emailed to the appropriate user.  My mail function works fine when it is not in the function, but that doesn't work for me because i need the user to double check their information, and then send.

 

//button with html link to finish page (html link works but the sendMail() function does not)

<a href="employee_hours_finish.php"><button type="submit" name="button2" id="button2" onclick="<?php sendMail() ?>">Send Hours</button></a>

 

//send mail function

<?php

function sendMail(){

      $to = "agregoire@123id.us";

$subject = "New Employee Time Card Submittal: " . $FirstName . " " . $LastName . " ";

$message =  "<h1>Employee Information</h1><br>" . $msg_head . "" . $msg_job1 . " ";

 

// set content-type for html email

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

 

// More headers

$headers .= 'From: <webmaster@rjzavoral.com>' . "\r\n";

 

mail($to,$subject,$message,$headers);

}

 

All of my variables are defined and 'mail($to,$subject,$message,$headers);' works fine when not in the function, but it sends the mail after the first button click to submit the form which is not what i want, i want it to submit to itself, check for errors, display the users information, then after another button click, send the mail.

 

I've tried making a button like this:

<input type="button" value="Send Hours" onclick="<?php sendMail() ?>" />

 

But i got the same result, the mail would not be sent.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.