4

I am trying to make a landing page and collect e-mail addresses from users.

First, I want to save e-mail addresses to a .txt file and I found an AJAX script, but the .txt file remains empty.

I then tried to write a php script to send an e-mail but it did not work.

I put my files on a free host, but cannot to send mails.

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);
 ?>
Mostafa Berg
  • 3,211
  • 22
  • 36

2 Answers2

3

Is there any output in your log files ?

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

Using your FTP client, try changing the text file permissions to 775, this will allow your scripts to open and write into it.

Here's a little PHP script that will add emails to the file (I changed it to fit 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);
}

?>
Mostafa Berg
  • 3,211
  • 22
  • 36
  • Here, I thought he was having trouble sending emails, not getting them into a text file. – crush Jun 13 '13 at 17:20
  • @user2483089 You're welcome, do you mean this doesn't work for you on localhost ? if not, how did you change the permissions ? and what's your OS ? – Mostafa Berg Jun 13 '13 at 17:22
  • @crush That's true, but he was initially trying to get it into a file, which makes more sense cause simply emailing every single email will be a mess to handle, better to have things in one place. – Mostafa Berg Jun 13 '13 at 17:23
  • @user2483089 can you update your question with the javascript code so we can take a look at it ? – Mostafa Berg Jun 13 '13 at 17:24
1

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

See this thread

Community
  • 1
  • 1
e.marten
  • 380
  • 3
  • 9