The Student Room Group

how to send something to users email on my website?

for example

say on my website a user fills out their email in a field.

once they click on the submit button, how do i send a file to their email ?

any ideas @UWS @IWMTom

Scroll to see replies

Reply 1
I believe this will only work if you have a mail client set up via hosting. This does not work if you set up your website locally

You will need to get the email address and pass it through some PHP. Assuming you have your mail client set up of course.

Look at the documentation for the mail() function.
http://php.net/manual/en/function.mail.php

https://stackoverflow.com/questions/5335273/how-to-send-an-email-using-php
(edited 6 years ago)
Original post by UWS
I believe this will only work if you have a mail client set up via hosting. This does not work if you set up your website locally

You will need to get the email address and pass it through some PHP. Assuming you have your mail client set up of course.

Look at the documentation for the mail() function.
http://php.net/manual/en/function.mail.php

https://stackoverflow.com/questions/5335273/how-to-send-an-email-using-php


this PHP stuff is completely new to me

any beginner tutorial ?
You could learn the fundamentals of PHP in a day or two on W3Schools (which I'd favour for).
(edited 6 years ago)
Reply 4
Original post by study beats
this PHP stuff is completely new to me

any beginner tutorial ?


[video="youtube;kY5P9sZqFas"]https://www.youtube.com/watch?v=kY5P9sZqFas[/video]

As I said though, the mail() function won't work if your website is hosted locally. Unless this is a hard requirement, you probably need to find an alternative to sending users a file.
Original post by Cholesterol
You could learn the fundamentals of PHP in a day or two on W3Schools (which I'd favour for).


i only wanna send email
Original post by UWS
[video="youtube;kY5P9sZqFas"]https://www.youtube.com/watch?v=kY5P9sZqFas[/video]

As I said though, the mail() function won't work if your website is hosted locally. Unless this is a hard requirement, you probably need to find an alternative to sending users a file.


what do you mean if my website is hosted locally ?

and what are the alternatives?

also is there just a php email tutorial?
Reply 7
Original post by study beats
what do you mean if my website is hosted locally ?

and what are the alternatives?

also is there just a php email tutorial?


Your PC is the host, I suspect you haven't paid for a live domain right?

I'm only aware of the mail() function using PHP.

Look at the stackoverflow link I have given you as well as the documentation.
Reply 8
Original post by study beats
for example

say on my website a user fills out their email in a field.

once they click on the submit button, how do i send a file to their email ?

any ideas @UWS @IWMTom


As @UWS has said, PHP is your best bet here, as it's already on practically every web hosting server going.

The mail() function can hook into a remote SMTP server, providing you know the information - this would allow you to send from a GMail address, for example.
Original post by UWS
Your PC is the host, I suspect you haven't paid for a live domain right?

I'm only aware of the mail() function using PHP.

Look at the stackoverflow link I have given you as well as the documentation.


i have a server i can upload my website too
Original post by IWMTom
As @UWS has said, PHP is your best bet here, as it's already on practically every web hosting server going.

The mail() function can hook into a remote SMTP server, providing you know the information - this would allow you to send from a GMail address, for example.


is there a simple tutorial i could follow to do this?
Reply 11
Original post by study beats
is there a simple tutorial i could follow to do this?


Read the documentation; it's self explanatory
As everyone has said, PHP is ideal. PHP only works on Linux so you'll need to get webhosting that is a Linux server and runs PHP (pretty much all of them) but it won't work on your home computer. I did a quick google, and here's a code, I've slightly altered it for you, you want to save the file with a .php extension. I've never tried sending an attachment through a PHP mailer though.



<?PHP
if(!$_POST[send]){
?>

<form method="POST">
Your Email:<input type="email" name="email" class="textbox"><br />
<input name="send" type="submit" id="send" value="Send">
</form>

<?PHP
}else{
$emailaddress = $_POST;

$email = new PHPMailer();
$email->From = '[email protected]';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( '$emailaddress' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();

}

?>




PS. I've not actually tried this particular script so I don't know how reliable it is, it's just something I've found on Google :smile:
(edited 6 years ago)
Reply 13
Original post by Whispers
As everyone has said, PHP is ideal. PHP only works on Linux so you'll need to get webhosting that is a Linux server and runs PHP (pretty much all of them) but it won't work on your home computer. I did a quick google, and here's a code, I've slightly altered it for you, you want to save the file with a .php extension. I've never tried sending an attachment through a PHP mailer though.






<?PHP
if(!$_POST[send]){
?>
<form method="POST">
Your Email:<input type="email" name="email" class="textbox"><br />
<input name="send" type="submit" id="send" value="Send">
<?PHP
}else{
$emailaddress = $_POST;

$email = new PHPMailer();
$email->From = '[email protected]';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( '$emailaddress' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();

}





Who on earth told you PHP only works on Linux based operating systems...
Original post by IWMTom
Read the documentation; it's self explanatory


i dont understand the documentation

is there anything else i can follow

i have looked online on youtube but they only provide tutorials for sending the form to your own personal email address rather than to the email thats been filled out in the field text
Reply 15
Original post by study beats
i dont understand the documentation

is there anything else i can follow

i have looked online on youtube but they only provide tutorials for sending the form to your own personal email address rather than to the email thats been filled out in the field text


You should probably learn the basics first, using a typical educational resource.

My advice to you is to focus on learning one language before jumping into another.
Original post by IWMTom
Who on earth told you PHP only works on Linux based operating systems...


I'm perhaps misinformed, and couldn't possibly tell you who had said it, I've always been lead to believe that if you want PHP you go for Linux, you want C+ you go for Windows. But then servers etc are too complex for my understanding, I only code websites as a hobby :biggrin:
Reply 17
Original post by Whispers
I'm perhaps misinformed, and couldn't possibly tell you who had said it, I've always been lead to believe that if you want PHP you go for Linux, you want C+ you go for Windows. But then servers etc are too complex for my understanding, I only code websites as a hobby :biggrin:


C+? You've lost me...
Original post by IWMTom
C+? You've lost me...


Have I? Oh dear :ciao:
Perhaps that's a good thing, as we are going a tad off topic :woo:
Reply 19
Original post by Whispers
Have I? Oh dear :ciao:
Perhaps that's a good thing, as we are going a tad off topic :woo:


Touché

Quick Reply

Latest