Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php EMAIL error

Options
  • 22-05-2009 2:06pm
    #1
    Registered Users Posts: 8,070 ✭✭✭


    [PHP]
    $fromx = $_GET["EMAIL"];


    if($fromx == null)
    {
    $xx = "noreply@company.ie";;
    }
    else
    {
    $xx = $_GET["EMAIL"];
    }

    $from = $xx;
    $to = "recipient@mail.com";
    $subject = "SALE now on !";

    sendHTMLemail($HTML,$from,$to,$subject);
    }


    function sendHTMLemail($HTML,$from,$to,$subject)
    {
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $headers .= "From: $from\r\n";

    if (mail($to,$subject,$HTML,$headers))
    {
    echo("Thank You");
    echo $from;
    echo "<br>";
    }
    else{echo("error");}
    }

    [/PHP]

    Keep getting error, unless i explicitly set $from to a string like "example@ss.com";


Comments

  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    What error are you getting?
    Are you sure that 'EMAIL' is being received by the form.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    you could verify if you are getting an email in the QS
    [php]
    $fromx = isset($_GET["EMAIL"]) ? trim($_GET["EMAIL"]) : "";
    if($fromx == "") die("No email available");
    [/php]


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    i printed it out, just made the code simpler there.
    And it prints either.

    Is there anyway i can identify what exactly the error is [printing the specific error] ?

    thanks


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    fis this php error first and see
    [php]
    $xx = "noreply@company.ie";; // double ;; should be single ;
    [/php]


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    Sorry i just made a typo since i was clearing up the code to post it up here.
    So ;; are not in my code.


  • Advertisement
  • Closed Accounts Posts: 1,200 ✭✭✭louie


    try this
    [php]
    $fromx = isset($_GET["EMAIL"]) && $_GET["EMAIL"] != "" ? $_GET["EMAIL"] : "noreply@company.ie";

    $from = $xx; //what's this supposed to be?
    $to = "recipient@mail.com";
    $subject = "SALE now on !";

    sendHTMLemail($HTML,$from,$to,$subject);


    function sendHTMLemail($HTML,$from,$to,$subject){
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From: $from\r\n";

    if (mail($to,$subject,$HTML,$headers)){
    echo "Thank You" . $from . "<br />";
    }else{
    echo "error sending email";
    }
    }
    [/php]


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    Thanks louie, basically cause the we use phplist to send newsletters from the explicitly define email, it was blacklisted buy our hoster, thus all the trouble ! :mad:

    when checking to see if variable is empty, will the following suffice ?


    [PHP]
    if (!isset($fromx) || ($fromx==null) || ($fromx==""))
    {
    $from = trim("explicitlyDefined@mail.com");

    }
    else
    {
    $from = trim($_GET["EMAIL"]);
    }[/PHP]


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    there is a simpler way
    [php]
    if (empty($fromx)){
    $from = trim("explicitlyDefined@mail.com");
    }else{
    $from = trim($_GET["EMAIL"]);
    }

    // or a quicker way
    $from = empty($fromx) ? "youremail@mail.ie" : trim($_GET["EMAIL"]);
    [/php]


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    actually, only after realising, the problem was that onSUBMIT, the get value dissappeared. Im assuming its cause the forum is post?

    so i passed it in as a hidden input field and then also good practice would be to have the forum action as <?php echo 'name.php?EMAIL='.$Getvar; ?>

    so the parameter stays after submission.


Advertisement