Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

e mail attachment problem

the mail() function

Moderators: macek, egami, gesf

e mail attachment problem

Postby mrelusive » Fri Jun 24, 2011 7:48 am

Hy everyone, i found lot of code in the internet for sending mail with attachment, but i not sucsed to make it to work.
Here is my code and if someone can help me i will bi thankefull to him.

<?php

$userName=$_POST["userName"];
$userEmail=$_POST["userEmail"];
$userComments=$_POST["userComments"];

$userAddress=$_POST["userAddress"];
$userPhone=$_POST["userPhone"];

$itemList=$_POST["itemList"];
$totalItems=$_POST["totalItems"];
$totalPrice=$_POST["totalPrice"];


$MailTo = "$userEmail, nidvanitri@msn.com";


$Subject = "Poruka";

$Body = "<font size=5><font color=#0066FF><b><u>Lista elemenata koriscenih u planeru</u>: </b></font></font><br><br><font size=2><B><font color=#0066FF>Od: </font></B>$userName<BR><font

size=2><B><font color=#0066FF>Address: </font></B>$userAddress<BR><B><font color=#0066FF>Telefon: </font></B>$userPhone<BR><font size=2><B><font color=#0066FF>Email: </font></B><A HREF=mailto:$userEmail>$userEmail</A><BR><BR><B><font color=#0066FF>Elementi: </font></B><BR>$itemList<BR><BR><BR><B><font color=#0066FF>Ukupno elemenata: </font></B>$totalItems<BR><B><font color=#0066FF>Ukupna cena: </font></B>$totalPrice<BR><BR><B><font color=#0066FF>Komentar korisnika: </font></B>$userComments<BR>";

$headers = "Content-type: text/html; charset=iso-8859-1\r\n";

$headers .= "From: Online planer";

$sendMail = mail($MailTo, "$Subject", "$Body", "$headers");

if(sendMail) {
echo ("&mailSent=USPELO!");}
else {
echo ("&mailSent=NEUSPELO!");}


?>
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am

Re: e mail attachment problem

Postby egami » Fri Jun 24, 2011 8:20 am

I don't usually do much with mail, but I'll give you a few tips and tricks since, I'm bored.

Code: Select all
// Adopted from someone on the web. I don't take credit for validEmail function
function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   
{
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || (checkdnsrr($domain,"A"))))
      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}

function formatPhone($phone = '', $convert = false, $trim = true)
{
    // If we have not entered a phone number just return empty
    if (empty($phone)) {
        return '';
    }

    // Strip out any extra characters that we do not need only keep letters and numbers
    $phone = preg_replace("/[^0-9A-Za-z]/", "", $phone);

    // Do we want to convert phone numbers with letters to their number equivalent?
    // Samples are: 1-800-TERMINIX, 1-800-FLOWERS, 1-800-Petmeds
    if ($convert == true) {
        $replace = array('2'=>array('a','b','c'),
                 '3'=>array('d','e','f'),
                     '4'=>array('g','h','i'),
                 '5'=>array('j','k','l'),
                                 '6'=>array('m','n','o'),
                 '7'=>array('p','q','r','s'),
                 '8'=>array('t','u','v'),                                '9'=>array('w','x','y','z'));

        // Replace each letter with a number
        // Notice this is case insensitive with the str_ireplace instead of str_replace
        foreach($replace as $digit=>$letters) {
            $phone = str_ireplace($letters, $digit, $phone);
        }
    }

    // If we have a number longer than 11 digits cut the string down to only 11
    // This is also only ran if we want to limit only to 11 characters
    if ($trim == true && strlen($phone)>11) {
        $phone = substr($phone, 0, 11);
    }

    // Perform phone number formatting here
    if (strlen($phone) == 7) {
        return preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1-$2", $phone);
    } elseif (strlen($phone) == 10) {
        return preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "($1) $2-$3", $phone);
    } elseif (strlen($phone) == 11) {
        return preg_replace("/([0-9a-zA-Z]{1})([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1($2) $3-$4", $phone);
    }

    // Return original phone if not 7, 10 or 11 digits long
    return $phone;
}

//Never ever take user input for what its worth.

function clean_it($input) { 
  $input 
= trim(strip_tags($input));
  return $input;
}

$userName = clean_it($_POST['userName']);
$userEmail = clean_it($_POST['userEmail']);
// 
if (!validEmail($userEmail)) { 
 die
("Email Not Valid");
}
 

$userComments 
= clean_it($_POST['userComments']);
$userAddress = clean_it($_POST['userAddress']);
$userPhone = preg_replace('/[^0-9]/','',$_POST['userPhone']);
$userPhone = formatPhone($userPhone);
$itemList = clean_it($_POST['itemList']);
$totalItems = clean_it($_POST['totalItems']);
$totalPrice = clean_it($_POST['totalPrice']); // although this can be handled differently

// Mail Stuff..
$MailTo = "$userEmail, nidvanitri@msn.com";
$Subject = 'Poruka';
$Body = "some html stuff here";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Online Planner <root@localhost>'."\r\n";

// for sending mail with an actual attachment please see http://us.php.net/manual/en/function.mail.php

$mailed = mail("$MailTo","$Subject","$Body","$headers");
if ($mailed) { 
  echo 
"YAY!";
}
 else { 
  echo 
"Woops! Mail Failed! $mailed";
}
 
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: e mail attachment problem

Postby mrelusive » Fri Jun 24, 2011 10:21 am

This script not working.
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am

Re: e mail attachment problem

Postby egami » Fri Jun 24, 2011 11:09 am

where's it dying?
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: e mail attachment problem

Postby mrelusive » Sat Jun 25, 2011 7:59 am

I don't know, just not working. Try to copy this code and replace my code with this and not working.
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am

Re: e mail attachment problem

Postby mrelusive » Mon Jun 27, 2011 1:54 am

Can anyone help?
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am

Re: e mail attachment problem

Postby azhagu » Mon Jun 27, 2011 4:20 am

mrelusive wrote:Can anyone help?


Reffer this link

http://techpdf.in/
azhagu
New php-forum User
New php-forum User
 
Posts: 13
Joined: Mon Jun 27, 2011 4:17 am

Re: e mail attachment problem

Postby mrelusive » Mon Jun 27, 2011 4:41 am

I see, and i was googling too, and found script that work too.
But i couldn't make my script and that or any other script to work together, because my script is taking data from sfw file and setup to do that.
I need someone to help me to make my script to send attachment. Attachment is one file and always one file like attach.png for example.
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am

Re: e mail attachment problem

Postby mrelusive » Tue Jun 28, 2011 12:22 am

Is it possible that no one can't help?
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am

Re: e mail attachment problem

Postby mrelusive » Wed Jun 29, 2011 9:46 am

HELP HELP HELP
mrelusive
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 24, 2011 7:43 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron