Jump to content

need help on my sendmail please


pixeltrace

Recommended Posts

guys,

 

i need help in my sendmail.

i have been seeking help here for 2 weeks already about this and unfortunately i still cant make it

work.

my sendmail scripts is working except that i wanted to have the emails addresses be in bcc

and right now i cant make it worked.

below is my codes for my blast.php page

<?php
session_start();
ob_start();
include '../db_connect.php';
include_once("FileUpload.php");
include_once("Functions.php");
$active = false;
$error = "";
$text = "List:
";

$subject = stripslashes($_POST['SUBJECT']);
$header = isset($_POST['FROM']) ? stripslashes($_POST['FROM']) : "JobHiRings<postmaster@jobhirings.com>";
$url = isset($_POST['URL']) ? stripslashes($_POST['URL']) : "";
// Clear All
if(isset($_POST['CANCEL'])){
   //unset($_SESSION['LIST']);
   unset($_SESSION['URL']);
}
// Clear URL Content
if(isset($_POST['CLEARURL']))unset($_SESSION['URL']);
if(isset($_POST['AMEND'])){
   $_SESSION['URL'] = stripslashes($_POST['URLPREVIEW']);
}
// Get URL Content
if(isset($_POST['GETURL'])){
   if(trim($_POST['URL']) == ""){
      $error = "Please fill in the url";
   }else{
      $file = fopen($_POST['URL'], "r") or exit("Invalid URL!");
      //Output a line of the file until the end is reached
      while(!feof($file))
        {
         $body .= fgets($file);
         //mail($email,"To $email", "Hi there!", "From: ncy@museik.net");
        }
      fclose($file);
      //$body = str_replace("%name%", "chuyang", $body);
      $_SESSION['URL'] = $body;
   }
}

if(isset($_POST['SEND'])){
//print_r($_POST);
$dbemail = array();
if ($_POST['to'] == "all"){
	$query = mysql_query("SELECT email FROM applicant WHERE subscribe = 'yes'") or die(mysql_error());
	while($row = mysql_fetch_array( $query )){
		$dbemail[] = $row['email'];
	}
}
if ($_POST['to'] == "notall"){
	$specialization = $_POST['specialization'];
	$query = mysql_query("SELECT email FROM applicant WHERE specialization LIKE '%".$specialization."%' AND subscribe = 'yes'") or die(mysql_error());
	while($row = mysql_fetch_array( $query )){
		$dbemail[] = $row['email'];
	};

}
if ($_POST['to'] == "peremail"){
	$dbemail[] = $_POST['email'];
}
//print_r($dbemail);

// After getting list of $dbemail, then send accordingly:
// : $mail->SendHTML($dbemail,$subject,$new_msg);
   if(trim($_POST['SUBJECT'] == ""))$error = "Please fill in a subject title";
   if($error == ""){
      require_once("Mail.php");
      $mail = new Mail();
      $mail->SetHeader($header);
  $bcc = implode(",", $dbemail);
  $to = "pixeltrace@gmail.com";
  $original_msg = $_SESSION['URL'];
  $mail->SendHTML($to,$subject,$original_msg);
  if(isset($_SESSION['LIST'])){
         
         foreach($_SESSION['LIST'] as $key=>$val){
            $new_msg = str_replace("%name%", $val[0], $original_msg);
		// See above
            $mail->SendHTML($val[1],$subject,$new_msg);
         }
         session_destroy();
         header("Location:$PHP_SELF");
      }
   }
}
if($active){
   $file = fopen("html.txt", "r") or exit("Unable to open file!");
   //Output a line of the file until the end is reached
   while(!feof($file))
     {
      $email .= fgets($file);
      
      //mail($email,"To $email", "Hi there!", "From: ncy@museik.net");
     }
   fclose($file);
   $email = str_replace("\"", "\\\"", $email);
   print $email;
   print "END";
}
//$bodytag = str_replace("'", "\'", $body);
echo $error;
?>
<script language="JavaScript">
function event_action(spl_value)
{
   if(spl_value=="peremail")
   {
      test.style.visibility="visible";
      test2.style.visibility='hidden';
   }
   else if(spl_value=="notall")
   {
      test2.style.visibility="visible";
      test.style.visibility='hidden';
   }
   else
   {
      test.style.visibility='hidden';
      test2.style.visibility='hidden';
   }
}
</script>
<link href="../../css.css" rel="stylesheet" type="text/css" />
<link href="../css.css" rel="stylesheet" type="text/css" />

<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="../images/spacer.gif" width="6" height="10" /></td>
    <td valign="top"><table width="216" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
      </tr>
      <tr>
        <td align="left" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
        <td width="214" valign="top"><form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
          <table  border="0" cellspacing="0" cellpadding="3">
            <tr>
              <td colspan="2" valign="top" nowrap="nowrap" class="text3"><img src="../images/spacer.gif" width="469" height="7" /></td>
              </tr>
            <tr>
              <td width="83" align="left" nowrap="nowrap" class="text3">Subject:</td>
              <td width="381" align="left"><input name="SUBJECT" type="text" id="SUBJECT" value="<?php print $subject;?>"  class="textfield1"></td>
            </tr>
            <tr>
              <td align="left" class="text3">From:</td>
              <td align="left"><input name="FROM" type="text" id="FROM" value="<?php print $header;?>" class="textfield1" /></td>
            </tr>
            <tr>
              <td align="left" class="text3">Sent to :</td>
              <td align="left"><span class="text7">
                <select name="to" class="textfield1" onchange="event_action(this.value);">
                  <option selected="selected" value="">--Email Option--</option>
                  <option value="all">Entire list</option>
                  <option value="notall">Specialization</option>
                  <option value="peremail">Individual Email</option>
                </select>
                <!--<input name="select" type="submit" id="select" value="select" />//-->
              </span></td>
            </tr>
            <!-- condition for the select menu -->
            <tr id="test2" style="visibility:hidden">
              <td align="left" class="text3">Specialization:</td>
              <td align="left"><select name="specialization" class="textfield1">
                  <option value="" selected="selected">-- Select Here --</option>
                  <?
         $uSql = "SELECT specialization FROM specialization";
         $uResult = mysql_query($uSql, $connection);
         if(!$uResult){
         echo 'no data found';
         }else{
         while($uRow = mysql_fetch_array($uResult)){
            ?>
                  <option value="<?= $uRow[specialization]?>">
                    <?= $uRow[specialization]?>
                    </option>
                  <?   }    } ?>
                </select>              </td>
            </tr>
            <tr id="test" style="visibility:hidden">
              <td align="left" class="text3">Email:</td>
              <td align="left"><input type="text" name="email" value="" class="textfield1" /></td>
            </tr>
            <!-- end -->
            <tr>
              <td align="left" class="text3">URL:</td>
              <td align="left"><input name="URL" type="text" id="URL" value="<?php print $url;?>" class="textfield1" /></td>
            </tr>
            <tr>
              <td> </td>
              <td align="left"><?php if(isset($_SESSION['URL'])){?>
                  <textarea name="URLPREVIEW" cols="60" rows="10" id="URLPREVIEW" class="textfield1"><?php print $_SESSION['URL']?></textarea>
                  <br />
                  <input name="CLEARURL" type="submit" id="CLEARURL" value="Clear" />
                  <input name="AMEND" type="submit" id="AMEND" value="Change" />
                  <?php }?>
                  <input name="GETURL" type="submit" id="GETURL" value="Get URL" />              </td>
            </tr>
            <tr>
              <td> </td>
              <td align="left"><input name="SEND" type="submit" id="SEND" value="Send" />
                  <input name="CANCEL" type="submit" id="CANCEL" value="Cancel" /></td>
            </tr>
            <tr>
              <td colspan="2"><span class="text3"><img src="../images/spacer.gif" width="469" height="7" /></span></td>
              </tr>
          </table>
        </form></td>
        <td align="right" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
      </tr>
      <tr>
        <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
      </tr>
    </table></td>
    <td><img src="../images/spacer.gif" width="6" height="10" /></td>
    <td valign="top"><table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="../images/spacer.gif" width="6" height="10" /></td>
        <td><table width="216" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
            </tr>
            <tr>
              <td align="left" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
              <td width="214" valign="top"> </td>
              <td align="right" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
            </tr>
            <tr>
              <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
            </tr>
        </table></td>
        <td><img src="../images/spacer.gif" width="6" height="10" /></td>
      </tr>
    </table></td>
  </tr>
</table>
<?php ob_end_flush();?>

 

and this is the code for my Mail.php page

<?php
class Mail
{
function Mail()
{
 // $this->headers = "From: CompanionSeek <Admin@localhost.com>";
  $this->headers = "From: JobHiRings<postmaster@jobhirings.com>";
}
function SendMail($to,$subject,$msg)
{
	$subject = stripslashes($subject);
	$msg = stripslashes($msg);
	$to = stripslashes($to);
	if(MAIL_ACTIVE)mail($to, $subject, $msg, $this->headers);
}

function SendHTML($to,$subject,$msg){
	$mime_boundary = uniqid("HTMLMESSAGE");
	$this->headers .= "\nMIME-Version: 1.0\nContent-Type: multipart/alternative; boundary=\"{$mime_boundary}\"";
	$this->headers .= "\nBCC: $bcc\"";

	//plain text version of message
	//HTML version of message
	$data = chunk_split(base64_encode($msg)); 
	$msg = 
	"--{$mime_boundary}\r\n" .
	"Content-Type: text/html; charset=ISO-8859-1\r\n" .
	"Content-Transfer-Encoding: base64\r\n\r\n".
	$data. "\n\n" . 
	"--{$mime_boundary}--\n"; 

	mail($to, $subject, $msg, $this->headers); 
}
function SetHeader($val){
	$this->headers = 'From: '.$val;

}
}
?>

 

 

hope you could help me with this.

currently the error that i am getting here is this

Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in c:\hosting\webhost4life\member\diorgrace\admean\email\Mail.php on line 32

 

thanks!

Link to comment
Share on other sites

hi,

 

i was able to make the bcc worked.

however i got another problem

on my first email blast you wont be seeing any errors

but the second time you blast an email

you will be getting this error message

Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in c:\hosting\webhost4life\member\diorgrace\admean\email\Mail.php on line 32

 

below is my code for the blast.php page

<?php
session_start();
ob_start();
include '../db_connect.php';
include_once("FileUpload.php");
include_once("Functions.php");
$active = false;
$error = "";
$text = "List:
";

$subject = stripslashes($_POST['SUBJECT']);
$header = isset($_POST['FROM']) ? stripslashes($_POST['FROM']) : "JobHiRings<postmaster@jobhirings.com>";
$url = isset($_POST['URL']) ? stripslashes($_POST['URL']) : "";
// Clear All
if(isset($_POST['CANCEL'])){
   //unset($_SESSION['LIST']);
   unset($_SESSION['URL']);
}
// Clear URL Content
if(isset($_POST['CLEARURL']))unset($_SESSION['URL']);
if(isset($_POST['AMEND'])){
   $_SESSION['URL'] = stripslashes($_POST['URLPREVIEW']);
}
// Get URL Content
if(isset($_POST['GETURL'])){
   if(trim($_POST['URL']) == ""){
      $error = "Please fill in the url";
   }else{
      $file = fopen($_POST['URL'], "r") or exit("Invalid URL!");
      //Output a line of the file until the end is reached
      while(!feof($file))
        {
         $body .= fgets($file);
         //mail($email,"To $email", "Hi there!", "From: ncy@museik.net");
        }
      fclose($file);
      //$body = str_replace("%name%", "chuyang", $body);
      $_SESSION['URL'] = $body;
   }
}

if(isset($_POST['SEND'])){
//print_r($_POST);
$dbemail = array();
if ($_POST['to'] == "all"){
	$query = mysql_query("SELECT email FROM applicant WHERE subscribe = 'yes'") or die(mysql_error());
	while($row = mysql_fetch_array( $query )){
		$dbemail[] = $row['email'];
	}
}
if ($_POST['to'] == "notall"){
	$specialization = $_POST['specialization'];
	$query = mysql_query("SELECT email FROM applicant WHERE specialization LIKE '%".$specialization."%' AND subscribe = 'yes'") or die(mysql_error());
	while($row = mysql_fetch_array( $query )){
		$dbemail[] = $row['email'];
	};

}
if ($_POST['to'] == "peremail"){
	$dbemail[] = $_POST['email'];
}
//print_r($dbemail);
print_r($dbemail);
//$to = "pixeltrace@gmail.com";
// After getting list of $dbemail, then send accordingly:
// : $mail->SendHTML($dbemail,$subject,$new_msg);

   if(trim($_POST['SUBJECT'] == ""))$error = "Please fill in a subject title";
   if($error == ""){
      require_once("Mail.php");
      $mail = new Mail();
      $email_list = implode(",", $dbemail);// change this
  print_r($email_list);
  $bcc = "Bcc: ".$email_list;//implode(",", $dbemail);
  $header.=" ".$bcc;
  $mail->SetHeader($header);
  $original_msg = $_SESSION['URL'];
  $mail->SendHTML("cvgnse@gmail.com",$subject,$original_msg);
   }
}

if($active){
   $file = fopen("html.txt", "r") or exit("Unable to open file!");
   //Output a line of the file until the end is reached
   while(!feof($file))
     {
      $email .= fgets($file);
      
      //mail($email,"To $email", "Hi there!", "From: ncy@museik.net");
     }
   fclose($file);
   $email = str_replace("\"", "\\\"", $email);
   print $email;
   print "END";
}
//$bodytag = str_replace("'", "\'", $body);
echo $error;
?>
<script language="JavaScript">
function event_action(spl_value)
{
   if(spl_value=="peremail")
   {
      test.style.visibility="visible";
      test2.style.visibility='hidden';
   }
   else if(spl_value=="notall")
   {
      test2.style.visibility="visible";
      test.style.visibility='hidden';
   }
   else
   {
      test.style.visibility='hidden';
      test2.style.visibility='hidden';
   }
}
</script>
<link href="../../css.css" rel="stylesheet" type="text/css" />
<link href="../css.css" rel="stylesheet" type="text/css" />

<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="../images/spacer.gif" width="6" height="10" /></td>
    <td valign="top"><table width="216" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
      </tr>
      <tr>
        <td align="left" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
        <td width="214" valign="top"><form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
          <table  border="0" cellspacing="0" cellpadding="3">
            <tr>
              <td colspan="2" valign="top" nowrap="nowrap" class="text3"><img src="../images/spacer.gif" width="469" height="7" /></td>
              </tr>
            <tr>
              <td width="83" align="left" nowrap="nowrap" class="text3">Subject:</td>
              <td width="381" align="left"><input name="SUBJECT" type="text" id="SUBJECT" value="<?php print $subject;?>"  class="textfield1"></td>
            </tr>
            <tr>
              <td align="left" class="text3">From:</td>
              <td align="left"><input name="FROM" type="text" id="FROM" value="<?php print $header;?>" class="textfield1" /></td>
            </tr>
            <tr>
              <td align="left" class="text3">Sent to :</td>
              <td align="left"><span class="text7">
                <select name="to" class="textfield1" onchange="event_action(this.value);">
                  <option selected="selected" value="">--Email Option--</option>
                  <option value="all">Entire list</option>
                  <option value="notall">Specialization</option>
                  <option value="peremail">Individual Email</option>
                </select>
                <!--<input name="select" type="submit" id="select" value="select" />//-->
              </span></td>
            </tr>
            <!-- condition for the select menu -->
            <tr id="test2" style="visibility:hidden">
              <td align="left" class="text3">Specialization:</td>
              <td align="left"><select name="specialization" class="textfield1">
                  <option value="" selected="selected">-- Select Here --</option>
                  <?
         $uSql = "SELECT specialization FROM specialization";
         $uResult = mysql_query($uSql, $connection);
         if(!$uResult){
         echo 'no data found';
         }else{
         while($uRow = mysql_fetch_array($uResult)){
            ?>
                  <option value="<?= $uRow[specialization]?>">
                    <?= $uRow[specialization]?>
                    </option>
                  <?   }    } ?>
                </select>              </td>
            </tr>
            <tr id="test" style="visibility:hidden">
              <td align="left" class="text3">Email:</td>
              <td align="left"><input type="text" name="email" value="" class="textfield1" /></td>
            </tr>
            <!-- end -->
            <tr>
              <td align="left" class="text3">URL:</td>
              <td align="left"><input name="URL" type="text" id="URL" value="<?php print $url;?>" class="textfield1" /></td>
            </tr>
            <tr>
              <td> </td>
              <td align="left"><?php if(isset($_SESSION['URL'])){?>
                  <textarea name="URLPREVIEW" cols="60" rows="10" id="URLPREVIEW" class="textfield1"><?php print $_SESSION['URL']?></textarea>
                  <br />
                  <input name="CLEARURL" type="submit" id="CLEARURL" value="Clear" />
                  <input name="AMEND" type="submit" id="AMEND" value="Change" />
                  <?php }?>
                  <input name="GETURL" type="submit" id="GETURL" value="Get URL" />              </td>
            </tr>
            <tr>
              <td> </td>
              <td align="left"><input name="SEND" type="submit" id="SEND" value="Send" />
                  <input name="CANCEL" type="submit" id="CANCEL" value="Cancel" /></td>
            </tr>
            <tr>
              <td colspan="2"><span class="text3"><img src="../images/spacer.gif" width="469" height="7" /></span></td>
              </tr>
          </table>
        </form></td>
        <td align="right" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
      </tr>
      <tr>
        <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
      </tr>
    </table></td>
    <td><img src="../images/spacer.gif" width="6" height="10" /></td>
    <td valign="top"><table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="../images/spacer.gif" width="6" height="10" /></td>
        <td><table width="216" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
            </tr>
            <tr>
              <td align="left" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
              <td width="214" valign="top"> </td>
              <td align="right" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td>
            </tr>
            <tr>
              <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td>
            </tr>
        </table></td>
        <td><img src="../images/spacer.gif" width="6" height="10" /></td>
      </tr>
    </table></td>
  </tr>
</table>
<?php ob_end_flush();?>

 

and this is the code in Mail.php page

<?php
class Mail
{
function Mail()
{
 // $this->headers = "From: CompanionSeek <Admin@localhost.com>";
  $this->headers = "From: JobHiRings<postmaster@jobhirings.com>";
}
function SendMail($to,$subject,$msg)
{
	$subject = stripslashes($subject);
	$msg = stripslashes($msg);
	$to = stripslashes($to);
	if(MAIL_ACTIVE)mail($to, $subject, $msg, $this->headers);
}

function SendHTML($to,$subject,$msg){
	$mime_boundary = uniqid("HTMLMESSAGE");
	$this->headers .= "\nMIME-Version: 1.0\nContent-Type: multipart/alternative; boundary=\"{$mime_boundary}\"";
	//$this->headers .= "\r\nBCC: ".$bcc;

	//plain text version of message
	//HTML version of message
	$data = chunk_split(base64_encode($msg)); 
	$msg = 
	"--{$mime_boundary}\r\n" .
	"Content-Type: text/html; charset=ISO-8859-1\r\n" .
	"Content-Transfer-Encoding: base64\r\n\r\n".
	$data. "\n\n" . 
	"--{$mime_boundary}--\n"; 

	mail($to, $subject, $msg, $this->headers); 
}
function SetHeader($val){
	$this->headers = 'From: '.$val;

}
}
?>

 

hope you could help me with this because its realy freaking me out.

 

thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.