Send invitation for meeting with Phpmailer

Asked

Viewed 477 times

0

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

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, when sending the email, send as an invitation so that when accepting mark also in the schedule of the email of who receives.

1 answer

-2

I’ve been playing with iCal recently, unfortunately I’ve done a lot of research and I haven’t found a way to make it possible for the invitation to be accepted automatically. It is necessary to accept the customer because if it would not be used these events for spam.

In my case I found it more feasible to schedule synchronization instead of sending invitations

Edit: sorry I didn’t see that you’re not using iCal

To send as an invitation you need to use the iCal format

Just use the example below within Phpmailer’s 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 search for iCal

Edit 2:

To send invitations by email it is necessary to send in the 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 date uid is the unique event identifier in the calendar attendees the participants

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

Example of using 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 variable content $cal is the same as what should be in the invite.ics attachment, as some emails require the content attached.

  • ????? the question was "But I intended, when sending the email, send as an invitation so that when accepting, mark also in the schedule of the email of who receives.". To send email as an invitation to a calendar you must use the ical standard.

  • Really, if that’s what you’re saying, you’re so confused that you didn’t even notice. Give an improved answer, to make it easier for those who have never heard of iCal, that it works with Phpmailer, give an example of how to call this data in Phpmailer, etc..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.