Php email script

I am trying to create a landing page and collect email addresses from users.

First, I want to save the email addresses in a TXT file, and I found an AJAX script, but the .txt file remains empty.

Then I tried to write a php script to send an email, but it did not work.

I put my files on a free host, but I can not send letters.

Here is my code!

HTML:

<form name="input" action="email.php" method="post"> <input type="text" name="email" placeholder="e-mail"> <input type="submit" name="submit" value="submit" id="submit" /> 

PHP:

 <?php $to = " my.email.adres@example.com "; $subject = "Hi!"; $body = "Send me info on :".$_POST["email"]; mail($to, $subject, $body); ?> 
+4
source share
2 answers

Is there any output in your log files?

For the first problem, your text file must have write permissions.

Using your FTP client, try changing the rights to text files to 775 , this will allow you to open and write your scripts.

Here is a little PHP script that will add letters to the file (I changed it according to your code)

 <?php $filename = "emails.txt"; if($_POST){ $email=strip_tags($_POST['email']); $email = substr($email, 0,50); $fp = fopen($filename, 'a'); fwrite($fp, $email."\r\n"); fclose($fp); } ?> 
+3
source

To send email through a PHP script, you need to set up an SMTP server (send email) or specify your own SMTP server.

Watch this stream

+1
source

Source: https://habr.com/ru/post/1486062/


All Articles