Jump to content

Generate outgoing email


Recommended Posts

Hi, guys and gals.Here's what I want to do in a nutshell. When visitors come to the site at www.sharekalamazoo.com we want them to be able to supply us with their friends' names and emails in order to send out an email from the site that directs their friends back to the site to view a "digital postcard".I think I can handle the PHP that gathers the data from site visitors and puts it in a MySQL DB. What I need to do then is have a pre-formatted email SENT OUT to the email address the people supply us with when they come to the site. How can this be done? Somewhat easily with PHP?Or are we better off to just have PHP send the data to a DB and use that data to just send out the emails ourselves?

Link to post
Share on other sites

Here's the REAL question, I guess:Can I use that MAIL function in PHP to gather data right from table form fields straight into an outgoing email --without a database?I was thinking I'd need to use PHP to get the form data to a database and then EXTRACT the same data for an outgoing email via a SEPERATE PHP script. But, can it just all be done with one PHP script, ba-da-bing? No need to send to database?Here's a sample of the form:http://www.sharekalamazoo.com/test.htmlTHANKS!

Link to post
Share on other sites

You can do whatever you want in one PHP script, there's not a limit on how many operations you're allowed to do. You can send an email, put it in the database, send it to your cell phone, page your dog, send it to your internet-enabled toaster, whatever you want to do. All the mail function does is actually send the email. The rest of the PHP script will be getting the data from the form and formatting the email text to send off. The w3schools site has a PHP forms tutorial, and there is also information in the PHP tips thread in this forum about how to get information from a form.

Link to post
Share on other sites
I think I can handle the PHP that gathers the data from site visitors and puts it in a MySQL DB. What I need to do then is have a pre-formatted email SENT OUT to the email address the people supply us with when they come to the site. How can this be done? Somewhat easily with PHP?
Are you saying:PA(PersonA) goes there, and types 'My freinds are PB and PC, and their emails are EB(EmailB) and EC'. And when PB and PC visit your site a day later, you want them to get an email sent to them.Or something else?If you are saying when there friend come to the site, you'll have to have the Email and names be saved in a web page using a simple fopen and fclose and then have the page with the EMails be deleted if they don't come in like 1 month or something using some unlink function... go here for more info: http://www.w3schools.com/php/php_ref_filesystem.asp(scroll to the bottom and look for the group of fsomething's)
Link to post
Share on other sites

I believe he wants people to enter their friend's names and email addresses and immediately have emails get sent to those people advertising the web site. All that's required for that is knowledge about how to process a form and how to use the mail function.

Link to post
Share on other sites

So, I have a form here:http://www.sharekalamazoo.com/test.htmlAnd I'm going to send the data from the form to sendmail.phpWhat I'm having trouble with is this: i cant seem to make one PHP file both GET the data from the form and turn it into a sendmial thing...The form only has like 3 fields, they are under these names:sendermailrecipientmmailmessageanybody got some simple code? I can handle formatting what goes in the outgoing mail.

Link to post
Share on other sites

mail($to, $subject, $message, $headers);You can set the variables to whatever you want. The to address might come from $_POST['recipientmail'], and the headers will need to have a From field.$headers = "From: {$_POST['sendermail']}";Check the mail reference page for more examples.

Link to post
Share on other sites

I'm trying this but it's not working, clearly I'm missing some critical stuff, here:

<?php// subject$subject = 'A postcard for you from Share Kalamazoo';// message$message = '<html><head>  <title>Your electronic postcard from sharekalamazoo(dot)com</title></head><body>  <p>A postcard awaits you at sharekalamazoo.com!</p>  <p>To view your postcard <a href="http://www.sharekalamazoo.com">click here</a>.      Or, copy and paste the URL below into your web browser.</p>          <p>http://www.sharekalamazoo.com</p>      </body></html>';// 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 = "To: {$_POST['recipientmail']}";$headers = "From: {$_POST['sendermail']}";$headers .= 'Cc: chadl@lamcreative.com' . "\r\n";// Mail itmail($to, $subject, $message, $headers);?>

Again this draws from the submit button on www.sharekalamazoo.com/test.html

Link to post
Share on other sites

Made a few mods to the headers.. still not working, though...

<?php// subject$subject = 'A postcard for you from Share Kalamazoo';// message$message = '<html><head>  <title>Your electronic postcard from sharekalamazoo(dot)com</title></head><body>  <p>A postcard awaits you at sharekalamazoo.com!</p>  <p>To view your postcard <a href="http://www.sharekalamazoo.com">click here</a>.      Or, copy and paste the URL below into your web browser.</p>          <p>http://www.sharekalamazoo.com</p>      </body></html>';// 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 = "To: {$_POST['recipientmail']}";$headers .= "From: {$_POST['sendermail']}";$headers .= 'Cc: chadl@lamcreative.com' . "\r\n";// Mail itmail($to, $subject, $message, $headers);?>

Link to post
Share on other sites

If i take out these two lines:

$headers .= "To: {$_POST['recipientmail']}";$headers .= "From: {$_POST['sendermail']}";

And define a specific email address in the $to field like so:

$to = 'chadl@lamcreative.com';

The PHP form works. Of course, what I need it to do is actually take the email addresses from the form, so it's of little use to me without those two header lines... Any ideas? The problem is either in the $to field or somewhere in the headers... unless it's in the FORM field of the form itself at www.sharekalamazoo.com/test.html

Link to post
Share on other sites

The two problems are that you didn't define $to (you did that later, it should be done in your other script), and the headers need to be separated with \r\n, per the specification. So instead of this:$headers = "To: {$_POST['recipientmail']}";$headers .= "From: {$_POST['sendermail']}";$headers .= 'Cc: chadl@lamcreative.com' . "\r\n";it should be this:$headers = "To: {$_POST['recipientmail']}\r\n";$headers .= "From: {$_POST['sendermail']}\r\n";$headers .= 'Cc: chadl@lamcreative.com';Make sure to set $to also.$to = $_POST['recipientmail'];

Link to post
Share on other sites

Well, it works now. Too good, in fact. Sometimes sends uot several emails, instead of just one.Here's the full PHP. Problem must be in the headers...

<?php$to = $_POST['recipientmail'];// subject$subject = 'A postcard for you from Share Kalamazoo';// message$message = '<html><head>  <title>Your electronic postcard from sharekalamazoo(dot)com</title></head><body>  <p>A postcard awaits you at sharekalamazoo.com!</p>  <p>To view your postcard <a href="http://www.sharekalamazoo.com">click here</a>.      Or, copy and paste the URL below into your web browser.</p>          <p>http://www.sharekalamazoo.com</p>      </body></html>';// 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 .= "To: {$_POST['recipientmail']}\r\n";$headers .= "From: {$_POST['sendermail']}\r\n";$headers .= 'Cc: chadl@lamcreative.com';header( 'Location: [url="http://www.sharekalamazoo.com/postcardconfirm'"]http://www.sharekalamazoo.com/postcardconfirm'[/url] ) ;// Mail itmail($to, $subject, $message, $headers);?>

Link to post
Share on other sites

Remove the To header, since you send the to address as a separate parameter. Some mail agents might send 2 emails that way. Also, if you're sending an email to the same address that's in the CC header you'll receive it twice.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...