Author Topic: A simpler PHP insertion script  (Read 20577 times)

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
A simpler PHP insertion script
« on: March 23, 2006, 01:03:31 am »
This very simple snippet of code will add a user to a list AND send the welcome or/and confirmation emails.

Code: [Select]
<?php
// don't forget to urlencode() the first and last name
$url "http://example.com/mail/signup.php?list=1&email=$payer_email&fname=$first_name&lname=$last_name&seq=1&del=0";
$lmp fopen($url,'r');
fclose($lmp);
?>


The following will allow overwriting of duplicates in case you're using this to welcome buyers of your products:

Code: [Select]
<?php
// don't forget to urlencode() the first and last name
$url "http://example.com/mail/signup.php?list=1&email=$payer_email&fname=$first_name&lname=$last_name&seq=1&del=0&overwritedupes=1";
$lmp fopen($url,'r');
fclose($lmp);
?>
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

jed

  • Posts: 18
    • View Profile
A simpler PHP insertion script
« Reply #1 on: August 21, 2006, 09:38:06 am »
Hi Dean,

I'm working on a contact form processor that uses your insertion script - however it doesn't appear to be inserting the data to the database.

Here's my form code:

Code: [Select]
// don't forget to urlencode() the first and last name
urlencode($fname);
$url = "http://www.domain.co.uk/mail/signup.php?list=1&email=$payer_email&fname=$first_name&seq=1&del=0&overwritedupes=1";
$lmp = fopen($url,'r');
fclose($lmp);

List id=1 exists in Listmail pro.
The form doesn't throw any errors - user is forwarded to thank you page - just that the first name and email are not added as expected.

Can you help?

Thanks.

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
A simpler PHP insertion script
« Reply #2 on: August 21, 2006, 10:34:46 am »
To make sure everything is formatted correctly I'd be interested to see the value of the $url variable just before it's passed to fopen().  Also, you might want to add an error message, ie:
Code: [Select]
     $url = "http://www.domain.co.uk/mail/signup.php?list=1&email=$payer_email&fname=$first_name&seq=1&del=0&overwritedupes=1";
      echo "LMPURL=$url<br>";
      $lmp = fopen($url,'r');
      if(!$lmp) echo "LMPERROR=Didn't open URL?<br>";
      fclose($lmp);
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

jed

  • Posts: 18
    • View Profile
A simpler PHP insertion script
« Reply #3 on: August 21, 2006, 11:28:29 am »
Okay I replaced:

Code: [Select]

      urlencode($fname);
      $url = "http://www.domain.co.uk/mail/signup.php?list=1&email=$payer_email&fname=$first_name&seq=1&del=0&overwritedupes=1";
      $lmp = fopen($url,'r');
      fclose($lmp);


with:

Code: [Select]

 urlencode($fname);
$url = "http://www.domain.co.uk/mail/signup.php?list=1&email=$payer_email&fname=$first_name&seq=1&del=0&overwritedupes=1";
      echo "LMPURL=$url<br>";
      $lmp = fopen($url,'r');
      if(!$lmp) echo "LMPERROR=Didn't open URL?<br>";
      fclose($lmp);


I get the following:

Quote
LMPURL=http://www.domain.co.uk/mail/signup.php?list=1&email=&fname=&lname=&seq=1&del=0&overwritedupes=1

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/folder/php/product.php:170) in /var/www/html/folder/php/product.php on line 194


So it seems that $payer_email and $first_name are stripped out but fopen() is working correctly.

Any ideas?

Thanks.

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
A simpler PHP insertion script
« Reply #4 on: August 21, 2006, 06:01:09 pm »
There's your problem right there.  What you need to do is change $payer_email to $email and $first_name to $fname.

When it's working as expected go ahead and remove (or comment, with // in front) the echo lines.

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

jed

  • Posts: 18
    • View Profile
A simpler PHP insertion script
« Reply #5 on: August 22, 2006, 04:20:01 am »
thanks Dean. Works like a charm.

krypton1

  • Posts: 17
    • View Profile
A simpler PHP insertion script
« Reply #6 on: October 23, 2006, 10:25:04 pm »
The code is working, and the user gets added, but it displays ugly looking warnings on the page:


Warning: fopen() [function.fopen]: HTTP request failed! HTTP/1.1 403 Forbidden in /homepages/18/d177540450/htdocs/file.php on line 52

Warning: fopen(http://www.domain.com/newsletter/signup.php?list=2&email=b%40b.com&fname=bbb&seq=1&del=0) [function.fopen]: failed to open stream: Success in /homepages/18/d177540450/htdocs/file.php on line 52


Any ideas?

Brian

krypton1

  • Posts: 17
    • View Profile
A simpler PHP insertion script
« Reply #7 on: October 24, 2006, 10:40:05 am »
I was able to solve this myself.  In case it happens to others, here is my solution:

Code: [Select]

$url = "http://www.domain.com/newsletter/signup.php?list=2&email=".urlencode($_POST['email'])."&fname=".urlencode($_POST['fname'])."&seq=1&del=0";
$ch = curl_init($url);
curl_exec($ch);
curl_close($ch);