The Student Room Group

how to send something to users email on my website?

Scroll to see replies

Original post by IWMTom
Touché


PS. Thank you though, your reply prompted me to go and look into Windows servers a little more, and I have learned something that PHP can in fact be ran on their servers, so it's given me some more knowledge. It's just a shame you were very snarky and sharp with me instead of being nice and informing me I was wrong. "Educate me, don't belittle me".
Thanks anyway though, for now I've gained a little more knowledge :biggrin::u::h::ahee:
Reply 21
Original post by Whispers
PS. Thank you though, your reply prompted me to go and look into Windows servers a little more, and I have learned something that PHP can in fact be ran on their servers, so it's given me some more knowledge. It's just a shame you were very snarky and sharp with me instead of being nice and informing me I was wrong. "Educate me, don't belittle me".
Thanks anyway though, for now I've gained a little more knowledge :biggrin::u::h::ahee:


Bless, don't get offended because I'm blunt - it's just how I am, I love you really!!

Windows servers are trash btw :colondollar:
Original post by IWMTom
Bless, don't get offended because I'm blunt - it's just how I am, I love you really!!

Windows servers are trash btw :colondollar:


I've always had that impression :laugh::laugh: and avoided them because of it.
Reply 23
Original post by Whispers
I've always had that impression :laugh::laugh: and avoided them because of it.


There's a good reason Linux based servers dominate the web hosting industry haha
Original post by IWMTom
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.


would i need to learn all the basics even if all i need is the mailing part?
It's worth noting that the mail() function can be very easily abused by spammers. Some web hosts will have it disabled. You may want to look at a third party like MailChimp for ease of use if that's the case or if you're very new.
Reply 26
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


Just read the documentation, example #4 is what you're after. I used it for my dissertation without any problems and I knew nothing about PHP beforehand.
Reply 27
Original post by study beats
would i need to learn all the basics even if all i need is the mailing part?


yes

Because otherwise when you want to know how to do something else you won't have the basics behind you.

Walk first, then run.
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">
</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:




hi,

thanks for providing the code, so how does it work?

i already have a text field and submit button in my html document, so how do i connect those two?

also does this code send the text that goes inside the body to the email address that is filled out in the text field ?
Original post by UWS
Just read the documentation, example #4 is what you're after. I used it for my dissertation without any problems and I knew nothing about PHP beforehand.


i am looking at example 4 right now

as i am looking at it i can see where the message goes and who the email is coming from

how do i mail it to the address that is typed in my fieldbox which is in the html file?
Original post by Paracosm
It's worth noting that the mail() function can be very easily abused by spammers. Some web hosts will have it disabled. You may want to look at a third party like MailChimp for ease of use if that's the case or if you're very new.


i dont understand?
Original post by Doonesbury
yes

Because otherwise when you want to know how to do something else you won't have the basics behind you.

Walk first, then run.


i think i may have done it, just need to know how to make it work now
If in the even emails are going to spam/junk you want to look at your DNS records and properly configure the SPF record (if misconfigured) to allow the SMTP server to be authorised to send on behalf of the domain
Reply 33
Original post by Aidan.reed
If in the even emails are going to spam/junk you want to look at your DNS records and properly configure the SPF record (if misconfigured) to allow the SMTP server to be authorised to send on behalf of the domain


I think email reputation is the least of OPs worries right now :laugh:
Original post by IWMTom
I think email reputation is the least of OPs worries right now :laugh:


You're correct.
(edited 6 years ago)
Original post by IWMTom
I think email reputation is the least of OPs worries right now :laugh:


do you want to look at my code to see if its done right?

also does my entire html document need to be in php format before i can upload it to a server?
Original post by Aidan.reed
If in the even emails are going to spam/junk you want to look at your DNS records and properly configure the SPF record (if misconfigured) to allow the SMTP server to be authorised to send on behalf of the domain


what?....
Reply 37
Original post by study beats
do you want to look at my code to see if its done right?

also does my entire html document need to be in php format before i can upload it to a server?


Generally, yes, you need to save the document as a .php file
Original post by IWMTom
Generally, yes, you need to save the document as a .php file


below is the php script file



1.

<?php

2.

// Multiple recipients

3.

$to = $_POST['email'];// note the comma

4.

// Subject

5.

$subject = 'Birthday Reminders for August';

6.

// Message

7.

$message = '

8.

<html>

9.

<head>

10.

<title>Birthday Reminders for August</title>

11.

</head>

12.

<body>

13.

sample text

14.

</body>

15.

</html>

16.

';

17.

// To send HTML mail, the Content-type header must be set

18.

$headers[] = 'MIME-Version: 1.0';

19.

$headers[] = 'Content-type: text/html; charset=iso-8859-1';

20.

// Additional headers

21.

$headers[] = 'To: Mary <[email protected]>, Kelly <[email protected]>';

22.

$headers[] = 'From: Birthday Reminder <[email protected]>';

23.

$headers[] = 'Cc: [email protected]';

24.

$headers[] = 'Bcc: [email protected]';

25.

// Mail it

26.

if($_POST){

27.

mail($to, $subject, $message, implode("\r\n", $headers));

28.

}

29.

?>










Below is the html code :



<form action="email_script.php" method="post"> <label for="email">Enter your email below to receive newsletter</label>
<input type="text" name="email" id="email">
<button id="emailButton"> send me newsletter </button> </form>





would this for if i was to test it on a server?
Original post by UWS
Just read the documentation, example #4 is what you're after. I used it for my dissertation without any problems and I knew nothing about PHP beforehand.


the php script is in the pastebin below:

https://pastebin.com/xkMpemSu

would this work with the code given below in a different html file:

<form action="email_script.php" method="post">
<label for="email">Enter your email below to receive newsletter</label>
<input type="text" name="email" id="email">
<button id="emailButton"> send me newsletter </button> </form>


and yes i have a server i can upload to , what are the next steps if the given code is correct?

Quick Reply

Latest