I need to be able to fetch an email address from the user and then use php to send them an email with a link. I know there are some implementations using jquery or AJAX but i have no experience in either of those topics. I was hoping for something simple. thanks
-
4What have you tried? Have you done some minimal research or just give me code? – ka_lin Mar 25 '13 at 00:04
-
A good start would be to read about jQuery or AJAX, then figure out some code, and then ask us what's wrong if it doesn't work. – Jonast92 Mar 25 '13 at 00:20
-
This is for a school project, i dont have the time to read up on jQuery or AJAX although i am interested in it. – Curious Learner Mar 25 '13 at 00:25
-
but stackoverflow is not for some home works – rsz Mar 25 '13 at 00:29
-
You seem to be trying to get people on stackoverflow to do your homework for you. This is not what you should be doing. If you want people to help you at least get an idea of what you want done. Not just 'I need this done' – Eli Stone Mar 25 '13 at 00:51
-
Why do you think i am asking people to do my homework for me. I am asking questions to help with certain part of my homework. Why is it peopel always assume i havent done any research. If i am asking a question it's because i have not found anything that i can understand. The project is extremely complex and i have already worked through many of the other hoops. Please cut me some slack. I have a lot to do on limited resources because my professor insists on not teaching and just assigning. – Curious Learner Mar 25 '13 at 00:58
3 Answers
"I need to be able to fetch an email address from the user"
Create a 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 then use php to send them an email with a link"
The submit button within the form will POST the value of the input field to the PHP script emailHandler.php
"I know there are some implementations using jquery or AJAX but i have no experience in either of those topics"
You don't need jQuery or AJAX for this, jQuery and AJAX are javascript topics (in which case, AJAX is about having you fetched the value from the HTML, then POST them to a PHP backend, and receive a JSON object which will tell the javascript whether it was successful or not, this is obiously NOT REQUIRED here but it CAN be used), you can simply use the built in PHP mail function: http://php.net/manual/en/function.mail.php
in emailHandler.php.
I like to do it like this:
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the 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 do something like this in emailHandler.php:
$email = isset($_POST['emailInput']) ? $_POST['emailInput'] : false;
if($email != false)
{
$yourEmail = "example@example.com";.
$subject = "Link";
$message = "The link and some message";
$success = sendMail($email, $yourEmail, $subject, $message);
}
In some cases you have to modify the PHP ini file, you can do it like 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');
". . I was hoping for something simple. thanks"
If this wasn't simple, then I don't know what is. If you wan't to make it complex, using jQuery and Ajax, then read about them online (or take a look at my profile, I've given out a lot of full working code that works with it).

- 4,964
- 1
- 18
- 32
-
Can i have two forms on the same site, while i send this email i also need to retrieve some data from an xml site and parse it into a website table. – Curious Learner Mar 25 '13 at 01:14
-
-
You shouldn't need another form to retrieve some data from an xml site to parse it into a website table. You could: a) Use jQuery and AJAX to do so, and make it first send the email and then populate the table, b) Create the table above the form with some php cod or c) Keep the form and the table in a separate file. – Jonast92 Mar 25 '13 at 09:11
If you are trying to send an email in a form, you can just do this to the form action and the rest are similar. Hope it helps(:
<form action="MAILTO:name@email.com" method="post" enctype="text/plain">

- 26
- 2
- 6
-
i would use the form however it needs to be server side and also i need the page to not be changed. The content needs to remaind there. – Curious Learner Mar 25 '13 at 00:27
PHP has a mail function. You will need to configure the php.ini for this though.

- 5,749
- 10
- 55
- 99
-
He will not need to, It's optional and actually depends on the circumstances. He could also use iniset, to modify it, but I guess it comes down to the same conclusion, just a different approach of thinking. – Jonast92 Mar 25 '13 at 00:20
-
I just need to be able to receieve the email address from the HTML and then have php send an email. – Curious Learner Mar 25 '13 at 00:26
-
@Jonast92, I agree. Curious Learner, to receive the email address you can use simple HTML ( using form field ), and then on the action page of the form, use the PHP mail function to send the mail to the retrieved email address. – rgamber Mar 25 '13 at 00:36
-
The problem is i cannot use the form submit action as this only one part of the website. I need the rest of the content to stay there. – Curious Learner Mar 25 '13 at 00:40
-
You don't need anything to stay anywhere, you can make it flow across the website like water, and use it whenever you need it. – Jonast92 Mar 25 '13 at 00:45
-
As Jonast92 said. You can use jQuery or Dojo for that. Eg. ContentPane in dojo has a href attribute which can be used to update certain content in the website. It is a good alternative to iframes. Though you cannot use addresses outside your domain, you can still trigger a php to send an email without using a form or switching pages. There might be simpler alternatives, but this is what comes to my mind. – rgamber Mar 25 '13 at 00:53
-