Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Please help me to set up php emails to be sent to different person

  1. #1
    Join Date
    Apr 2007
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Please help me to set up php emails to be sent to different person

    PHP Code:
    ?php
    $to 
    "me@headache.com";
    $subject "hi how are you";
    $body "helllo hello this is test.. this is test ........";
    $headers "From: mail@mail.co.uk\r\n" .
        
    "X-Mailer: xxxx LONDON";
    if (
    mail($to$subject$body$headers)) {
      echo(
    "<p>Message sent!</p>");
     } else {
      echo(
    "<p>Message delivery failed...</p>");
     }
    ?> 
    Hello friends,

    I want to send this email to different users.

    I already have variables like

    emails: <?=$row['email_add'] ?>
    body: <?=$row['noteforstudents'] ?>

    I just want different person to receive email according to the details above. Do I need to set up session or require_once for this ?

    I don't know how to setup pls help

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    so basically you would like to send it to this person AND yourself correct?

    you can do something like this

    PHP Code:
    // Creates an array of emails to send
    $receip = array('me@headache.com');
    $receip[] = $_POST['email'];
    // Declare rest of email properties
    ...

    // Declare error and success sent arrays
    $error = array();
    $success = array();

    // Checks if email can be sent to each person, then puts address in appropriate array
    foreach($receip as $to)
         if( !
    mail($to$subject$body$headers) )
         {
              
    $error[] = "Cannot Send Email To "$to ."! Please try again later";
         }
         else 
         {
              
    $success[] = "Email Sent Successfully To "$to ."! Thank You.";
         }
    }

    // Checks and prints error emails
    if(isset($error)) {
         echo 
    "\n<ul>";
         foreach(
    $error as $err)
         {
                echo 
    "\n\t<li>"$err ."</li>";
         }
         echo 
    "\t</ul>";
    }

    // Checks and prints successful emails sent
    if(isset($success)) {
         echo 
    "\n<ul>";
         foreach(
    $success as $succ)
         {
                echo 
    "\n\t<li>"$succ ."</li>";
         }
         echo 
    "\n</ul>";


    now if you are grabbing them from the database you can replace
    Code:
    $receip[] = $_POST['email'];
    with
    Code:
    $receip[] = $row['email_add'];

  3. #3
    Join Date
    Apr 2007
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Hi boogyman

    i made a sendmail.php file using
    PHP Code:
    ?php
    $to 
    "me@headache.com";
    $subject "hi how are you";
    [
    B]$body "helllo hello this is test.. this is test ........";[/B]
    $headers "From: mail@mail.co.uk\r\n" .
        
    "X-Mailer: xxxx LONDON";
    if (
    mail($to$subject$body$headers)) {
      echo(
    "<p>Message sent!</p>");
     } else {
      echo(
    "<p>Message delivery failed...</p>");
     }
    ?> 
    then I get
    helllo hello this is test.. this is test .......
    on my email message

    but when I used
    PHP Code:
    <?php
    $to 
    "webmaster@placett.co.uk";
    $subject "You have received feedback from LONDON";
    [
    B]$body $row['noteforstudents'];    [/B]    
    $headers "From: an@angliancollege.co.uk\r\n" .
        
    "X-Mailer:LONDON";
    if (
    mail($to$subject$body$headers)) {
      echo(
    "<p>Message sent!</p>");
     } else {
      echo(
    "<p>Message delivery failed...</p>");
     }
    ?>
    I don't know why it's not sending the message now, I get empty message box. while $row['noteforstudents']; has got some message on it.

    Please help

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    $body = $row['noteforstudents'];
    the [b] should cause an error every time. That is bbCode, not php. I am not sure why you would like to bold the entire message but you can do something like
    Code:
    $body = "<strong>".$row['noteforstudents']."</strong>";
    and that will create the bold weight that it would appear you were trying to do.

    now what do you mean empty message box? like there is no body of the message or it doesnt send the message at all? If you are getting an empty message box try to output on the page the portion that is empty
    Code:
    if (mail($to, $subject, $body, $headers)) {
      echo("<p>Message sent!</p>");
      echo($row['noteforstudents']);
     } else {
      echo("<p>Message delivery failed...</p>");
     }
    and see what that produces. if there is nothing there, then its not recognizing anything being in that field, thus you would need to check your process and make sure everything is named correctly without any typos

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by boogyman View Post
    the [b] should cause an error every time. That is bbCode, not php.
    I think the user was just trying to show what code he/she is talking about; not that it is in the code itself.

    Question to the OP, do have a query to the database in order to get the information? If not, you will need to do this.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Apr 2007
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    $body $row['noteforstudents']; 
    This code did work on the same page as there are other codings and the mail goes everytime the page refresh or when i enter the page.

    But when i move this page to another php page like something.php it doesn;t pull the data from the database, any help would be greatful


    Code:
    <?php
    $to = "memem@gmail.com";
    $subject = "This is a email feedback from me";
    $body = $row['noteforstudents'];
    $headers = "From: ashfh@djd.co.uk\r\n" .
    "X-Mailer: xxxx LONDON";
    if (mail($to, $subject, $body, $headers)) {
    echo("<p>Message sent!</p>");
    } else {
    echo("<p>Message delivery failed...</p>");
    }
    ?>

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    move it how?

    nothing will be retrieved from the database unless you have established a connection, and have selected the appropriate database you wish to collect information from.

    if you are still having this dilemma after reviewing the above can you please post your code? so we can better help you troubleshoot.

  8. #8
    Join Date
    Apr 2007
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I did just made a newpage with sendmail.php

    and the page contains only

    Code:
    <?php
    $to = "memem@gmail.com";
    $subject = "This is a email feedback from me";
    $body = $row['noteforstudents'];
    $headers = "From: ashfh@djd.co.uk\r\n" .
    "X-Mailer: xxxx LONDON";
    if (mail($to, $subject, $body, $headers)) {
    echo("<p>Message sent!</p>");
    } else {
    echo("<p>Message delivery failed...</p>");
    }
    ?>
    On the above page nothing comes from the database,

    then with my little knowledge I tried to include config.php page where database details are located, now it says

    Code:
    <?
    	require_once "config.inc.php";
    
    	
    	if (isset($_SESSION['id']))
    	{
    		$sql = "select * from applications where id='$_SESSION[id]'";
    		$rs = mysql_query($sql) or SQLError("Getting all the details...");
    		$row = mysql_fetch_array($rs);
    		unset($_SESSION['id']);
    	}
    	else
    	{
    		 echo("<p>still not conecting databse ...</p>");
    	}
    
    ?>
    
    
    
    
    <?=$row['noteforstudents'] ?>
    
    <?php
    $to = "me@mail.com";
    $subject = "This is a email feedback for studenst";
    $body = $row['noteforstudents'];
    $headers = "From: laura@.co.uk\r\n" .
        "X-Mailer: xxxx LONDON";
    if (mail($to, $subject, $body, $headers)) {
      echo("<p>Message sent!</p>");
     } else {
      echo("<p>Message delivery failed...</p>");
     }
    ?>

    Now it;s gives me this error

    still not conecting databse ...

    Message sent!
    I am doing all this blindly Forgive me for my ignorance but i need serious hel.

    Thank you very much.

  9. #9
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    you are getting the note from the database correct?

    you are getting
    still not conecting databse ...
    because the session 'id' variable is not set.
    I am assuming that you are creating the session variable in your config.inc.php file which you are including.
    You need to figure out where the session variable is being initiated, and if you have started a session in the first place.


    if you want to take the 'noteforstudents' from the user form then it would be a different code.

  10. #10
    Join Date
    Apr 2007
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    you are getting the note from the database correct?

    That's correct.

    How do I set the session variables ?

    The session in config.inc.php is set as follows

    PHP Code:
    <?
        session_start
    ();
        
    $s_self_page substr ($_SERVER["PHP_SELF"], strrpos$_SERVER["PHP_SELF"], "/" ) + 1);
        
    $s_db_link NULL;
        
    $SQLdebug_g true;
        
    /**
        *--------------------------------
        *Here is all server configurarions
        *MySQL Server
        *--------------------------------
        */
        
    define ("C_MYSQL_HOST""host");
        
    define ("C_MYSQL_USER""user");
        
    define ("C_MYSQL_PWD""pass");
        
    define ("C_MYSQL_DB""db");

        
    define ("C_HTTP_ROOT""http://www.mysite.com" );
        
    define ("C_VIRTUAL_ROOT""folder/" );
        
        
    define ("C_PAGE_HEADING""abcdef");

        
    define ("C_ADMIN_USERNAME""user" );
        
    define ("C_ADMIN_PASSWORD""password.." );

        
    define ("C_RESULTS_PER_PAGE"30);
        
    define ("C_AD_RESULTS_PER_PAGE"10);
        
        
    //Time Difference
        
    define ("C_TIME_DIF", +5*60*60);//In seconds
        
        //Rooms display
        
    define ("C_DISPLAY_LENGTH"15);
        
    define ("C_DEFAULT_BG""#f9f9f9");
        
    define ("C_BG_COL_1""#FFCC00");
        
    define ("C_BG_COL_2""#99FF00");

        
    header ("Cache-Control: private");
        
    header ("Pragma: no-cache");
        
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •