Jump to content

PHP newsletter coding help


LalinM

Recommended Posts

I have this double opt-in newsletter code and everything works until the point where the subscriber has to click the confirmation link. Clicking the link brings the subscriber to the 'unable to confirm' page (confirm-ko.htm). i.e user couldn't be added to the list. Also I'm supposed to get an email when someone signs up but I don't get anything at all. My webhost supports PHP 5.2.

 

Here's the newsletter code (newsletter.html):

<link href="NL-style.css" rel="stylesheet" type="text/css">

<form name="form1" method="post" action="NL-process.php">

<table border="0" cellpadding="10" cellspacing="5" class="tbmain">

  <tr>

    <td class="left">E-mail:</td>

    <td><input name="email" type="text" class="text"></td>

  </tr>

  <tr>

    <td colspan="2"><p align="center" class="text">A confirmation email will

        be <br>

        sent to you to verify your address</p>

      <p align="center">

        <input type="submit" name="Submit" value="Send" class="btn">

        <br>

  </tr>

</table>

</form>

 

code for NL-process.php:

 

<?php

 

$emailmanager = '';

$email = $_GET ['email'];

$emailmanager = $_GET['emailmanager'];

$id = $_POST['id'];

$msg = $_POST['msg'];

$headers = $_POST['headers'];

$k = $_POST['k'];

$v = $_POST['v'];

$body = $_POST['body'];

$Ok = $_POST ['Ok'];

 

 

$scriptUrl = 'http://www.mydomain.com/NL-confirm.php';

 

//    These are the positive and negative reply pages URLs

 

$urlok = 'NL-ok.htm'; //subscribe successful.click confirmation //mail.

$urlko = 'NL-ko.htm'; // invalid email address. go back.

 

error_reporting(1);

 

set_magic_quotes_runtime (0);

if (get_magic_quotes_gpc()) {

foreach($_POST as $k=>$v)

    $_POST[$k] = stripslashes($v);

foreach($_COOKIE as $k=>$v)

    $_COOKIE[$k] = stripslashes($v);

}

 

$msg = '';

foreach($_POST as $k=>$v) {

if (strtolower($k) != "submit" && trim($v) != '')

    $msg .= "$k:$v

";

}

 

$id = md5($msg);

setcookie("sb$id",$msg,time()+86400,'','',0);

 

$email = trim($_POST['email']);

 

$body = "Thank you for your subscription!

 

In order to confirm your request, please click

on the following link or copy it in your browser

(use the same browser you used for subscribing):

 

$scriptUrl?email=$email&id=$id

 

If you didn't ask for this subscription please ignore this message.

";

 

 

$Ok = ereg("^([a-zA-Z0-9_.-]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$", $email);

if ($Ok) {

mail($email,'Please confirm your subscription',$body,'From: '.$emailmanager);

Header("Location: $urlok");

} else {

Header("Location: $urlko");

}

?>

 

NL-confirm.php code:

 

<?php

 

$emailmanager = '';

$email = $_GET['email'];

$emailmanager =$_GETT['emailmanager'];

$id = $_POST['id'];

$msg = $_POST['msg'];

$headers = $_POST['headers'];

$k = $_POST['k'];

$v = $_POST['v'];

$body = $_POST['body'];

$Ok = $_POST['Ok'];

 

//    These are the positive and negative reply pages URLs

 

$urlok = 'confirm-ok.htm'; // you have been added to the list

$urlko = 'confirm-ko.htm'; // unable to add to list either your // email is invalid or you subscribed after one day

 

error_reporting(1);

set_magic_quotes_runtime (0);

if (get_magic_quotes_gpc()) {

foreach($_POST as $k=>$v)

    $_POST[$k] = stripslashes($v);

foreach($_COOKIE as $k=>$v)

    $_COOKIE[$k] = stripslashes($v);

}

 

$msg = $_COOKIE['sb'.$_GET['id']];

 

$email = trim($_GET['email']);

$Ok = ereg("^([a-zA-Z0-9_.-]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$", $email);

 

$headers  = 'From: ' . $email . "

";

$headers .= 'MIME-Version: 1.0' ."

";

$headers .= 'Content-Type: text/plain; charset=iso-8859-1' ."

";

$headers .= 'Content-Transfer-Encoding: 8bit'. "

 

";

 

if ($Ok && ($msg != '')) {

mail($emailmanager,'Subscribe',$msg,$headers);

Header("Location: $urlok");

} else {

Header("Location: $urlko");

}

?>

 

 

I'm new to PHP so please try to go easy on the jargon.

 

Thanks for the help.

 

 

Link to comment
https://forums.phpfreaks.com/topic/207595-php-newsletter-coding-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.