0
    require_once( './PHPMailer-master/PHPMailerAutoload.php');
    $mail = new PHPMailer();
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.office365.com';
    $mail->ClearReplyTos();
    $mail->addReplyTo($organizer_email, $organizer);// Specify main and backup server
    $mail->SetFrom('xyx@xyx.com', 'zyx');
    $mail->SMTPAuth = tls;                               // Enable SMTP authentication
    $mail->Username = 'xyz@xyz.com';                   // SMTP username
    $mail->Password = 'xyzzzzz';               // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    $mail->Port = 587;                                    //Set the SMTP port number - 587 for authenticated TLS
    $mail->addAddress($organizer_email);  // Add a recipient
    $content = file_get_contents($resume_attach_path);
    $content = chunk_split(base64_encode($content));
    $eol = "\r\n";
    $tags = explode(',', $to);
    foreach ($tags as $tag) {
        $mail->addCC($tag);
    }
    $mail->WordWrap = 50;        
    $mail->Subject = $subject;
    $mail->Body = $desc;
    $mail->AltBody = $text; // in your case once more the $text string
    $mail->Ical = $text; // ical format, in your case $text string 
    $mail->isHTML(true); // Set email format to HTML       
    //$mail->addStringAttachment($resume_attach_path,'base64');
    if ($mail->send()) {
       return true;
    }else{
        return false;
    }

if i use addAttachment i can just see the attachment, cannot see the ical invite ,but if i remove the attachment i can see the ical invite,how can i send both inline ical and external document attachment in phpmailer.

dude
  • 4,532
  • 8
  • 33
  • 51
  • What are doing messing about with headers and content encoding for? PHPMailer does all that for you. You can call `addAttachment` and `addEmbeddedAttachment`. You're not setting a from address; you don't need to call `clearReplyTos`. Calling `msgHTML` overwrites both `Body` and `AltBody`, so there's no point in setting them beforehand. Some basic reading of [documentation](https://github.com/PHPMailer/PHPMailer/wiki) would probably help. – Synchro Dec 20 '16 at 08:15
  • can you show a sample code @Synchro – dude Dec 20 '16 at 09:18
  • 1
    Look at the samples provided with PHPMailer and described in the docs - they're not doing anything different. Just apply a little logic to what you're doing - don't just call random functions, set random strings, apply random encodings. – Synchro Dec 20 '16 at 11:19
  • @Synchro i read the documents and tried all types... it just working the same... if i add addAttachment i am missing the ical and if i remove addAttachment i get the invite inline,it will be helpful if u provide a code for it. thanks in advance – dude Dec 20 '16 at 11:26
  • "An iCal message part body. Only supported in simple alt or alt_inline message types" check phpmailer's source search for `Ical` and you'll see why it's left out if you add an attachement – cske Dec 22 '16 at 17:44
  • @cske i am not able to see the ical message part body when i add an attachment – dude Dec 22 '16 at 18:10

2 Answers2

0

I am showing you a simple working example here

    <?php
function sendMail($subject, $body, $name, $email, $attachment = null){
        $mail = new PHPMailer(true);
        $mail->IsSMTP(); // telling the class to use SMTP
        $mail->SMTPAuth = true; // enable SMTP authentication
        $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
        $mail->Host = "**************"; // sets GMAIL as the SMTP server
        $mail->Port = 465; // set the SMTP port for the GMAIL server
        $mail->Username = "*************"; // GMAIL username
        $mail->Password = "***********"; // GMAIL password

         //Typical mail data
        $mail->AddAddress($email, $name);
        $mail->SetFrom('*********', '************');
        $mail->Subject = $subject;      
        $mail->Body = $body;
        $mail->IsHTML(true);
        if($attachment){            
             $mail->AddAttachment($attachment['tmp_name'],
                         $attachment['name']);
        }
        try{

            $mail->Send();

        } catch(Exception $e){
            //Something went bad
            // print_r($e);
            echo "Fail :(";
            die;
        }
    }
?>

In this code $attachment is $_FILES['file']. How to call this function is given below.

sendMail($subject, $body, $name, $email, $_FILES['file']);

To use Ical in mailer see a Stackoverflow Question

Community
  • 1
  • 1
Aabir Hussain
  • 1,161
  • 1
  • 11
  • 29
  • i have tried this... this just shows the attachment not the inline... u cannot show both inline and attachment – dude Dec 25 '16 at 17:17
  • ok did you also try `$mail->addAttachment('/calendar_file.ics');` and have look github issue -> https://github.com/PHPMailer/PHPMailer/issues/175 – Aabir Hussain Dec 26 '16 at 10:57
0

According to comment in PHPMailer code:

Only supported in simple alt or alt_inline message types

when you add other attachments, part of adding Ical file based on Ical property is ommited.

yergo
  • 4,761
  • 2
  • 19
  • 41