Simple way to send email with javascript and PHP -
i need able fetch email address user , use php send them email link. know there implementations using jquery or ajax have no experience in either of topics. hoping simple. thanks
"i need able fetch email address user"
create form:
<form action="emailhandler.php" method="post" id="emailform"> <label for="emailinput">email: </label> <input type="text" name="emailinput" id="emailinput" value="" /> <input type="submit" id="submitemail" value="submit email" /> </form>
"and use php send them email link"
the submit button within form post value of input field php script emailhandler.php
"i know there implementations using jquery or ajax have no experience in either of topics"
you don't need jquery or ajax this, jquery , ajax javascript topics (in case, ajax having fetched value html, post them php backend, , receive json object tell javascript whether successful or not, obiously not required here can used), can use built in php mail function: http://php.net/manual/en/function.mail.php
in emailhandler.php.
i like this:
function spamcheck($field) { //filter_var() sanitizes e-mail //address using filter_sanitize_email $field=filter_var($field, filter_sanitize_email); //filter_var() validates e-mail //address using filter_validate_email if(filter_var($field, filter_validate_email)) { return true; } else { return false; } } function sendmail($toemail, $fromemail, $subject, $message) { $validfromemail = spamcheck($fromemail); if($validfromemail) { mail($toemail, $subject, $message, "from: $fromemail"); } }
and in emailhandler.php:
$email = isset($_post['emailinput']) ? $_post['emailinput'] : false; if($email != false) { $youremail = "example@example.com";. $subject = "link"; $message = "the link , message"; $success = sendmail($email, $youremail, $subject, $message); }
in cases have modify php ini file, can this:
ini_set('smtp' , 'smtp.example.com'); ini_set('smtp_port' , '25'); ini_set('username' , 'example@example.com'); ini_set('password' , 'password'); ini_set('sendmail_from' , 'example@example.com');
". . hoping simple. thanks"
if wasn't simple, don't know is. if wan't make complex, using jquery , ajax, read them online (or take @ profile, i've given out lot of full working code works it).
Comments
Post a Comment