SOLVED: Problem with mail function -$from

the mail() function

Moderators: macek, egami, gesf

cerkoxxl
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Jan 10, 2012 5:58 am

SOLVED: Problem with mail function -$from

Postby cerkoxxl » Sat Mar 24, 2012 3:37 am

Hi. I use the code, at the bottom, for send easy message form website for years and have not had any problems so far. Now, the fiend of my wanted to insert this code to his website on different server nad the variable $from do not run properly. When I inset this code to any other website on any other different servers, everithing is OK (mail name, value from, message). But on his server the value of variable $form is not the the value form Imput "Email", but allways "xz000500@useron4.hostmaster.sk". Am I do something wrong? Or how can I solve this problem? Thanks.

Code: Select all

<?php
/* ****************************UTF-8************************************** */
function autoUTF($s)
{
    if (preg_match('#[\x80-\x{1FF}\x{2000}-\x{3FFF}]#u', $s)) // detect UTF-8
    {
        return $s;
    }
    elseif (preg_match('#[\x7F-\x9F\xBC]#', $s)) // detect WINDOWS-1250
    {
        return iconv('WINDOWS-1250', 'UTF-8', $s);
    }
    else // assume ISO-8859-2
    {
        return iconv('ISO-8859-2', 'UTF-8', $s);
    }
}

function cs_mail($to, $predmet, $zprava, $head = "")
{
    $predmet = "=?utf-8?B?".base64_encode(autoUTF($predmet))."?=";
    $head .= "MIME-Version: 1.0\n";
    $head .= "Content-Type: text/plain; charset=\"utf-8\"\n";
    $head .= "Content-Transfer-Encoding: base64\n";
    $zprava = base64_encode(autoUTF($zprava));
    return mail($to, $predmet, $zprava, $head);
}
/* ********************************************************************** **  */

$from = "From: $email\r\n";

cs_mail("mymail@mymail.sk","Správa zo stránky  www.transportexpert.sk","Táto správa bola vygenerovaná z online systému:\n
---------------------- Správa ------------------------\n
Meno: " . $_POST['meno'] . "\n
Telefón: " . $_POST['cislo'] . " \n
Mail: " . $_POST['email'] . " \n
Text správy: " . $_POST['sprava'] . " \n
------------------------------------------------------ \n
",$from);

include("sent.html");

?>
Last edited by cerkoxxl on Tue Mar 27, 2012 3:59 am, edited 1 time in total.

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Problem with mail function -$from

Postby freshnet » Sat Mar 24, 2012 3:47 am

It sounds like the 'email from' variable is set at the server level. That can be changed in php.ini, I believe the key to be changed is sendmail_from.

cerkoxxl
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Jan 10, 2012 5:58 am

Re: Problem with mail function -$from

Postby cerkoxxl » Mon Mar 26, 2012 8:51 am

Thanks for your point.
I checked the php setting on both servers and found differencies in sentmail settings. So I ask webhosting provider to help me solve this problem.
It was good point, thanks.

cerkoxxl
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Jan 10, 2012 5:58 am

Re: Problem with mail function -$from

Postby cerkoxxl » Tue Mar 27, 2012 3:57 am

SOLVED:
the problem was PHP version 5.3 which do not alow global variables so I had to define variable $email = $_POST['email']; and then I can call this variable.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest