Exemple #1
0
 /**
  * Initialize this instance
  * @access private
  */
 function initialize()
 {
     $this->IsSMTP();
     global $adb;
     $result = $adb->pquery("SELECT * FROM vtiger_systems WHERE server_type=?", array('email'));
     if ($adb->num_rows($result)) {
         $this->Host = $adb->query_result($result, 0, 'server');
         $this->Username = $adb->query_result($result, 0, 'server_username');
         $this->Password = $adb->query_result($result, 0, 'server_password');
         $this->SMTPAuth = $adb->query_result($result, 0, 'smtp_auth');
         if (empty($this->SMTPAuth)) {
             $this->SMTPAuth = false;
         }
         $this->ConfigSenderInfo($adb->query_result($result, 0, 'from_email_field'));
         $this->_serverConfigured = true;
         $this->Sender = getReturnPath($this->Host);
     }
 }
function sendmail($to, $from, $subject, $contents, $mail_server, $mail_server_username, $mail_server_password, $filename, $smtp_auth = '')
{
    $mail = new PHPMailer();
    $mail->Subject = $subject;
    $mail->Body = $contents;
    //"This is the HTML message body <b>in bold!</b>";
    $initialfrom = $from;
    $mail->IsSMTP();
    // set mailer to use SMTP
    //$mail->Host = "smtp1.example.com;smtp2.example.com";  // specify main and backup server
    $mail->Host = $mail_server;
    // specify main and backup server
    if ($smtp_auth == 'true') {
        $mail->SMTPAuth = true;
    } else {
        $mail->SMTPAuth = false;
    }
    $mail->Username = $mail_server_username;
    //$smtp_username;  // SMTP username
    $mail->Password = $mail_server_password;
    //$smtp_password; // SMTP password
    $mail->From = $from;
    $mail->FromName = $initialfrom;
    $mail->AddAddress($to);
    // name is optional
    $mail->AddReplyTo($from);
    $mail->WordWrap = 50;
    // set word wrap to 50 characters
    $mail->IsHTML(true);
    // set email format to HTML
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
    $mail->Sender = getReturnPath($mail->Host, $mail->From);
    if (!$mail->Send()) {
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        exit;
    }
}
Exemple #3
0
/**	Function to set all the Mailer properties
  *	$mail		-- reference of the mail object
  *	$subject	-- subject of the email you want to send
  *	$contents	-- body of the email you want to send
  *	$from_email	-- from email id which will be displayed in the mail
  *	$from_name	-- from name which will be displayed in the mail
  *	$to_email	-- to email address  -- This can be an email in a single string, a comma separated
  *			   list of emails or an array of email addresses
  *	$attachment	-- whether we want to attach the currently selected file or all files.
  				[values = current,all] - optional
  *	$emailid	-- id of the email object which will be used to get the vtiger_attachments - optional
  */
function setMailerProperties($mail, $subject, $contents, $from_email, $from_name, $to_email, $attachment = '', $emailid = '', $module = '', $logo = '')
{
    global $adb;
    $adb->println("Inside the function setMailerProperties");
    if ($module == "Support" || $logo == 1) {
        $mail->AddEmbeddedImage('themes/images/logo_mail.jpg', 'logo', 'logo.jpg', "base64", "image/jpg");
    }
    $mail->Subject = $subject;
    $mail->Body = $contents;
    //$mail->Body = html_entity_decode(nl2br($contents));	//if we get html tags in mail then we will use this line
    $mail->AltBody = strip_tags(preg_replace(array("/<p>/i", "/<br>/i", "/<br \\/>/i"), array("\n", "\n", "\n"), $contents));
    $mail->IsSMTP();
    //set mailer to use SMTP
    //$mail->Host = "smtp1.example.com;smtp2.example.com";  // specify main and backup server
    setMailServerProperties($mail);
    //Handle the from name and email for HelpDesk
    $mail->From = $from_email;
    $rs = $adb->pquery("select first_name,last_name from vtiger_users where user_name=?", array($from_name));
    $num_rows = $adb->num_rows($rs);
    if ($num_rows > 0) {
        $from_name = getFullNameFromQResult($rs, 0, 'Users');
    }
    $mail->FromName = decode_html($from_name);
    $mail->Sender = getReturnPath($mail->Host, $from_email);
    if ($to_email != '') {
        if (is_array($to_email)) {
            for ($j = 0, $num = count($to_email); $j < $num; $j++) {
                $mail->addAddress($to_email[$j]);
            }
        } else {
            $_tmp = explode(",", $to_email);
            for ($j = 0, $num = count($_tmp); $j < $num; $j++) {
                $mail->addAddress($_tmp[$j]);
            }
        }
    }
    //commented so that it does not add from_email in reply to
    //$mail->AddReplyTo($from_email);
    $mail->WordWrap = 50;
    //If we want to add the currently selected file only then we will use the following function
    if ($attachment == 'current' && $emailid != '') {
        if (isset($_REQUEST['filename_hidden'])) {
            $file_name = $_REQUEST['filename_hidden'];
        } else {
            $file_name = $_FILES['filename']['name'];
        }
        addAttachment($mail, $file_name, $emailid);
    }
    //This will add all the files which are related to this record or email
    if ($attachment == 'all' && $emailid != '') {
        addAllAttachments($mail, $emailid);
    }
    //If we send attachments from Reports
    if ($attachment == 'attReports') {
        if (isset($_REQUEST['filename_hidden_pdf'])) {
            $file_name = $_REQUEST['filename_hidden_pdf'];
            addAttachment($mail, $file_name, $emailid);
        }
        if (isset($_REQUEST['filename_hidden_xls'])) {
            $file_name = $_REQUEST['filename_hidden_xls'];
            addAttachment($mail, $file_name, $emailid);
        }
    }
    $mail->IsHTML(true);
    // set email format to HTML
    $mail->AllowEmpty = true;
    //allow sent empty body.
    return;
}