SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Angry Help with functions and mail function

    Hi,

    I am using this very simple code but all emails which are being sent are coming blank. I am using this same code for last few months and its working absolutely fine but today suddenly it has stopped working.

    First I have these really 2 simple functions:

    Code:
    function loadtemplate ($filename)
    {
            $handle = fopen($filename, "r");
            $tmpcontent = fread($handle, filesize($filename));
            fclose($handle);
    
            return $tmpcontent;
    }
    
    function sendmail ($fromname, $frommail, $toname, $tomail, $subject, $message)
    {
            $headers = "MIME-Version: 1.0\r\n";
            $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
            $headers .= "To: " . $toname . " <" . $tomail . ">\r\n";
            $headers .= "From: " . $fromname . " <" . $frommail . ">\r\n";
    
            mail ($tomail, $subject, $message, $headers);
    }
    As you can see the first function i.e: loadtemplate reads the specified file and returns the content. Simple.

    The second function is simply sending the mail using php's mail function. Simple.

    Now my script:

    Code:
    <?php
    require_once ("functions.php");
    
    if (isset($_POST["btnGo"]))
    {
            $message = loadtemplate("templates/RegMailTemplate.txt");
            sendmail ("From Someone", "you@yourmail.com", $_POST["fullname"], $_POST["email"], "Test Subject", $message);
    
            echo "<p>Mail Sent</p>";
    }
    ?>
    
    <form method="post">
    <input type="text" name="fullname" /><br />
    <input type="text" name="email" /><br />
    <input type="submit" name="btnGo" value="Go" />
    </form>
    Simple code:
    Enter full name and email in form and press Go button then in code it loads the function file and using the loadtemplate function i am loading a simple text file which is loading fine (I echoed the $message variable and its workign fine).

    Now using the 2nd function sendmail I am trying to send the mail. All is working fine except the mail is blank. The text file's content which I have loaded into variable $message is not coming in the mail. Why ?

    I have tried alot of ways but it won't just work. Please help me. This is making me crazy.

  2. #2
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Never mind i fixed it. Was a issue in my mail template file. Silly me.

    Thanks.


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
  •