Jump to content

Recommended Posts

So, I dont know very much about php. Most projects I work on require simple mods of existing scripts, and I can usually figure out(with enough hours) how to fix glitches, bugs etc.  This however is driving me crazy.

I'm setting up a "MySpace" type site for a client.  I've had a pretty gnarly crash course so far and have learned a lot.  However this one thing is killing me. 

Anyway, there is a section on the site where you can invite members from outside the community to join.  You can add as many email address as you like and it will outsend invitation to the recipients.  The emails are separated with commas.

Now heres the glitch. If you try to input a single email address, it gives an error message.  Or, If you have more than one address(say 10), only the ones AFTER the first comma(the last 9) will be sent.  The only way to send ONE email address is by typing it in with a comma preceding it, like ",mike@jones.com".  Ive scoured the code and think this is the script handling the emailing....Anyone have any ideas how I can fix it?

$emails=form_get("emails");
  $subject=form_get("subject");
  $mes=form_get("mes");

  $emails=ereg_replace("\r","",$emails);
  $emails=ereg_replace("\n","",$emails);
  $emails=ereg_replace(" ","",$emails);
  $email=",".$email;
  $email=split(",",$emails);
  $email=if_empty($email);
  $data[0]=$subject;
  $now=time();
  if($email!=''){
  show_header();
  echo "<table width=100% class='body'>
  <tr><td class='lined title'>Invitation</td>
  <tr><td class='lined'>";

Any help would be sooooooo appreciated..

Link to comment
https://forums.phpfreaks.com/topic/13429-please-help-my-emailer-please/
Share on other sites

Just in case that wasn't enough...here's more of the source code...

  //getting values
  $emails=form_get("emails");
  $subject=form_get("subject");
  $mes=form_get("mes");

  $emails=ereg_replace("\r","",$emails);
  $emails=ereg_replace("\n","",$emails);
  $emails=ereg_replace(" ","",$emails);
  $email=",".$email;
  $email=split(",",$emails);
  $email=if_empty($email);
  $data[0]=$subject;
  $now=time();
  if($email!=''){
  show_header();
  echo "<table width=100% class='body'>
  <tr><td class='lined title'>Invitation</td>
  <tr><td class='lined'>";
  foreach($email as $addr){
  //if user is site member - standart invitation
      $sql_query2="select mem_id from members where email='$addr'";
      $num=sql_execute($sql_query2,'num');
      if($num!=0){

      $fr=sql_execute($sql_query2,'get');
      $sql_query="select mem_id from network where mem_id='$m_id' and frd_id='$fr->mem_id'";
      $num2=sql_execute($sql_query,'num');
      $sql_query="select mes_id from messages_system where
      (mem_id='$m_id' and frm_id='$fr->mem_id' and type='friend') or
      (mem_id='$fr->mem_id' and frm_id='$m_id' and type='friend')";
      $num=sql_execute($sql_query,'num');

  if($m_id==$fr->mem_id){
    echo "$addr: you can't invite yourself!</br>";
  }//if
  elseif($num>0){
    echo "$addr - you already invited this user.</br>";
  }//elseif
  elseif($num2>0){
    echo "$addr - this user is already your friend.</br>";
  }//elseif
  else {

      $subj="Invitation to Join ".name_header($m_id,$fr->mem_id)."\'s Personal Network";
      $bod="After you push \"Confirm\" button user ".name_header($m_id,$fr->mem_id).
      " will be added to your friends network.";
      $sql_query="insert into messages_system(mem_id,frm_id,subject,body,type,folder,date)
        values('$fr->mem_id','$m_id','$subj','$bod','friend','inbox','$now')";
        sql_execute($sql_query,'');

        echo "$addr: Invitation is sent.</br>";
  }//else

      }//if a user
      else {
      //if user is not site member - just sending email
      $sql_query="insert into invitations (mem_id,email,date) values ('$m_id','$addr','$now')";
      sql_execute($sql_query,'');
      $sql_query="select max(inv_id) as maxid from invitations";
      $max=sql_execute($sql_query,'get');
      $data[1]=$mes."
      <a href='$main_url'>$main_url</a></br>
      <a href='$main_url/index.php?mode=join&inv_id=$max->maxid'>$main_url/index.php?mode=join&inv_id=$max->maxid</a>";
      $data[2]=name_header($m_id,"ad");
      $sql_query="select email from members where mem_id='$m_id'";
      $k=sql_execute($sql_query,'get');
      $data[3]=$k->email;
      messages($addr,"6",$data);
      echo "$addr: Invitation is sent.</br>";
      }//else
  }//foreach
  echo "</td></table>";
  }//if
  else {
      error_screen(3);
  }//else
}//else
}//function
what is this code for as what i can see its like a tell a freind code.

and make all your varables names that are understandable to reflect your codeing.



i had a good look looks all fine except use eregi_replace not ereg_replace

also add $email=trim($email);

thats all the advice i can give  ok.

good luck.
It is a "tell a friend" code.  I'm using the Alstrasoft E-friends software.  It suck big time.  There are so many bugs its insane. 

It is the "Invite a friend" a friend page, where your supposed to be able to send an email message to someone inviting them to join the site.

I cannot for the life of me figure out why this refuses to work.  Like I said previously, it will only send an email if there is a comma in front of the email address.  So, if you fill in the field with one email address it will come back with a "please fill in required fields" error. And if you put in 3 email addresses, it will send all except for the 1st one(because the other two have commas in front of them).  What the hell!!!!
$email=",".$email;


take this line away or alter like this

$email="".$email;

$email // email varable

= // equal

"." // double quote with the ,

. caternation meaning add to $email varable.

so the programer has added a , to the beging of all email dam that bad good luck mate.
Well, the test is "can I put in an email address without a comma at the begining. 

If I remove or alter this line

$email=",".$email;

Nothing appears to change at all.

If I remove both those lines then I get "Please fill in required fields"  regardless of whether I have a comma or not.

However If I remove the second line only:
I get this error..

Warning: Invalid argument supplied for foreach() in /home/bakespac/public_html/friends/functions.php on line 567

Where we find this:

//deleting empty values of array
function if_empty($data){
$flag=0;
if($data==''){
  return '';
}//if
else{
$result=array();
$i=0;
foreach($data as $val){                    -------------------------->Line 567
  if((isset($val))&($i!=0)&($val!="")){
//if(!$val){
    $flag=1;
    array_push($result,$val);
  }//if
$i++;
}//foreach
if($flag==0){
  return '';
}//elseif
else {
  return $result;
}//else
}//else
}//function
function if_empty1($data){
$flag=0;
if($data==''){
  return '';
}//if
else{
$result=array();
$i=0;
foreach($data as $val){
  if($val){
//if(!$val){
    $flag=1;
    array_push($result,$val);
  }//if
$i++;
}//foreach
if($flag==0){
  return '';
}//elseif
else {
  return $result;
}//else
}//else
}//function


???
try this i made just know ok

<?php

$text = $emil;
$text = trim($text);
$text = substr($text, 1);
$text = rtrim($text, ',');


?>

has th same effect
<?
$text = $email;
$text = substr($text,1);
?>


and this if the, at the beging go away

<?php
$text = $email;

if(eregi("[\,]",$text) ) {

$text=str_replace(","," ",$text);

}
?>
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.