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 = "[email protected]";
 $subject = "Hi!";
 $body = "Send me info on :".$_POST["email"];

mail($to, $subject, $body);
 ?>
6
  • Did you configure your SMTP settings in your php.ini? Commented Jun 13, 2013 at 16:39
  • there is no closing <form> tag Commented Jun 13, 2013 at 16:39
  • You're also missing a fourth argument Headers in your mail() function. Commented Jun 13, 2013 at 16:43
  • @asprin - the headers argument is optional. Commented Jun 13, 2013 at 16:57
  • aspirin thank ok I add headers imulsion I forgot to copy. @crush no, how to do that and connect with email.php ? Commented Jun 13, 2013 at 16:59

2 Answers 2

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);
}

?>
Sign up to request clarification or add additional context in comments.

4 Comments

Here, I thought he was having trouble sending emails, not getting them into a text file.
@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 ?
@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.
@user2483089 can you update your question with the javascript code so we can take a look at it ?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.