Send meeting invitation with PHPMailer

0

When creating a new event in the calendar, it automatically sends an email to the person responsible for this event with the information that a new event has been marked like this:

try {
    $bdd = new PDO("mysql:host=$hostname;dbname=$database", $username, $password,
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
        //echo 'Conexao efetuada com sucesso!';
    }
catch(PDOException $e)
    {
        echo $e->getMessage();
    }
      if (isset($_POST['title']) && isset($_POST['contact']) && isset($_POST['start']) && isset($_POST['end']) && isset($_POST['color'])){

    $title = $_POST['title'];
    $contact = $_POST['contact'];
    $start = $_POST['start'];
    $end = $_POST['end'];
    $color = $_POST['color'];

    require ("phpmailer/class.phpmailer.php");
require ("phpmailer/class.smtp.php");

# Inicia a classe PHPMailer
$mail = new PHPMailer();

# Define os dados do servidor e tipo de conexão
$mail->IsSMTP(); // Define que a mensagem será SMTP
$mail->CharSet = 'utf-8';
$mail->Host = "smtp.gmail.com"; # Endereço do servidor SMTP, na WebHS basta usar localhost caso a conta de email esteja na mesma máquina de onde esta a correr este código, caso contrário altere para o seu desejado ex: mail.nomedoseudominio.pt
$mail->Port = 587; // Porta TCP para a conexão
$mail->SMTPSecure = 'tls';
$mail->SMTPAutoTLS = false; // Utiliza TLS Automaticamente se disponível
$mail->SMTPAuth = true; # Usar autenticação SMTP - Sim
$mail->Username = '[email protected]'; # Login de e-mail
$mail->Password = 'xxxxxxx'; // # Password do e-mail
# Define o remetente (você)
$mail->From = "[email protected]"; # Seu e-mail
$mail->FromName = "xxxxxxxxx"; // Seu nome
# Define os destinatário(s)
$mail->AddAddress('[email protected]', 'xxxxxxxxxxx'); # Os campos podem ser substituidos por variáveis
#$mail->AddAddress('[email protected]'); # Caso queira receber uma copia
#$mail->AddCC('[email protected]', 'Pessoa Nome 2'); # Copia
#$mail->AddBCC('[email protected]', 'Pessoa Nome 3'); # Cópia Oculta
# Define os dados técnicos da Mensagem
$mail->IsHTML(true); # Define que o e-mail será enviado como HTML
#$mail->CharSet = 'iso-8859-1'; # Charset da mensagem (opcional)
# Define a mensagem (Texto e Assunto)
$mail->Subject = "Marcações"; # Assunto da mensagem
$mail->Body = "Informo que tem uma nova marcação.
<html>
                        <head>
                        </head>
                        <body>
                        <h2>Marcação</h2>


                          <tr>
                            <th>Nome: ".$title."</th><p></br>
                            <th>Contacto: ".$contact."</th><p></br>
                            <th>Data Inicio: ".$start."</th><p></br>
                            <th>Data Fim: ".$end."</th><p></br>
                          </tr>

                        </body>
                        </html>";
$mail->AltBody = "Este é o corpo da mensagem de teste, somente Texto! \r\n :)";

# Define os anexos (opcional)
#$mail->AddAttachment("c:/temp/documento.pdf", "documento.pdf"); # Insere um anexo
# Envia o e-mail
$enviado = $mail->Send(); 
# Limpa os destinatários e os anexos
$mail->ClearAllRecipients();
$mail->ClearAttachments();

    $sql = "INSERT INTO eventsLar(title, contact, start, end, color, colaborador) values ('$title', '$contact', '$start', '$end', '$color', 'xxxxxx xxxxxxx')";

    echo $sql;

    $query = $bdd->prepare( $sql );
    if ($query == false) {
     print_r($bdd->errorInfo());
     die ('Erreur prepare');
    }
    $sth = $query->execute();
    if ($enviado) {
echo "E-mail enviado com sucesso!";
} else {
echo "Não foi possível enviar o e-mail.";
echo "<b>Informações do erro:</b> " . $mail->ErrorInfo;
}
    if ($sth == false) {
     print_r($query->errorInfo());
     die ('Erreur execute');
    }

}

But I wanted to send the email as an invitation, so that by accepting it, also mark the email address of the recipient.

    
asked by anonymous 14.09.2018 / 14:01

1 answer

-2

I've been messing with iCal recently, unfortunately I've researched a lot, and I have not found a way to be able to automatically accept the invitation. You need the client's acceptance because you would not be using those events for spam.

In my case I found it more feasible to synchronize the calendar instead of sending invitations

Edit: Sorry, I did not see that you're not using iCal

To send as invitation you need to use the iCal format

Just use the example below within the PHPMailer iCal function

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//ZContent.net//Zap Calendar 1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
SUMMARY:Abraham Lincoln
UID:c7614cff-3549-4a00-9152-d25cc1fe077d
ATTENDEE;RSVP=TRUE:mailto:[email protected]
SEQUENCE:0
STATUS:CONFIRMED
TRANSP:TRANSPARENT
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12
DTSTART:20080212
DTEND:20080213
DTSTAMP:20150421T141403
CATEGORIES:U.S. Presidents,Civil War People
LOCATION:Hodgenville\, Kentucky
GEO:37.5739497;-85.7399606
DESCRIPTION:Born February 12\, 1809\nSixteenth President (1861-1865)\n\n\n
 \nhttp://AmericanHistoryCalendar.com
URL:http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincol
 n
END:VEVENT
END:VCALENDAR

Edit with your need and for more information look for iCal

Edit 2:

To send invitations by email it is necessary to send in ical standardization as described above. To adapt it to your invitation it is necessary to modify the values of the fields, where:

dtstart and dtend refer to start and end dates uid is the unique event identifier in the calendar attendees participants

For more details generate an event in the Outlook calendar and send the email, download the ics and see the attributes generated.

Example usage with PHP Mailer:

// ...

//Attachments
    $mail->addAttachment('invite.ics');         // Add attachments

    //Content
    $mail->isHTML(false);                                  // Set email format to HTML
    $mail->Subject = 'treste7';
    $mail->Body    = 'teste';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->ContentType = 'application/ics';


    $cal = 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//bobbin v0.1//NONSGML iCal Writer//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20100701T080000Z
DTEND:20100701T110000Z
DTSTAMP:20091130T213238Z
UID:[email protected]
ATTENDEE;RSVP=TRUE:mailto:[email protected]
CREATED:20091130T213238Z
DESCRIPTION:Example event 1
LAST-MODIFIED:20091130T213238Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Example event 1
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART:20100701T120000Z
DTEND:20100701T130000Z
DTSTAMP:20091130T213238Z
UID:[email protected]
CREATED:20091130T213238Z
DESCRIPTION:Example event 2
LAST-MODIFIED:20091130T213238Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Example event 2
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR';

// Method: REQUEST, CANCEL
// Status: CONFIRMED, CANCELLED
    $mail->Ical = $cal;
    $mail->send();

Where the content of the $cal variable is the same as it should be in the invite.ics attachment, since some emails need the attached content.

    
14.09.2018 / 18:56