0

I've been trying to figure this out all day. I'm trying to create a simple back-end email interface that will allow user to enter a few fields and then mail off to several email recipients. I have figured out most of it with the exception of being able to create a link in the message. Please help. p.s. If there are suggestions for an entirely better way to do this, I'm open to them.Thank you, james.

my code:

$subj = "Try Our New Strawberry Bagels";
$chicken = $_POST['comments'];
$message = $chicken;



 // To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";


 while ($row = mysqli_fetch_assoc($result))
 {
  $emails = $row['email'] . ",";
  mail($emails, $subj, $message, $headers);
 }



?>

<form action="testMail.php" method="post">
                            Name: <input type="text" name="fname" />
                             Age: <input type="text" name="age" />
                           Comment:<textarea name="comments" 
                           id="comments">      </textarea>
                            <input type="submit" />
                            </form>
0

1 Answer 1

4

You're going to be spamming the heck out of the first whose name shows up in the database results. Most likely you'd want to move the mail() call OUTSIDE of your loop, you'll be sending to:

1st loop: [email protected],
2nd loop: [email protected], [email protected],
3rd loop: [email protected], [email protected], [email protected], 
etc...

You're also specifying in the mail headers that you're sending an HTML email, so just use html to specify the link.

$message = <<<EOL
<a href="http://example.com">Click here</a> for a strawberry bagel deal.
EOL;
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Marc. The first part of your response, when I move the mail() outside of the loop there are no emails sent out. The second part, I am trying to fill out a form and have the $_post come over and be used as a variable for the email message. I'm having a tough time having that variable contain a link, even with the content set up as HTML in the header. Thanks for the help

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.