• Resolved lanxalot

    (@lanxalot)


    Hello

    The website I am building is called The Stag’s Head Inn.

    In the automated emails that are generated the html code is shown instead of the apostrophe like this:

    Stag&# 039;s Head Inn (I had to add a space here for the code to show)

    Stag’s Head Inn is filled out on the ‘Reply-To Name’

    It is important for me to display the apostrophe in the message, can you please advise on a way I can fix the issue?

    I do not get the same issue when using other email forms.

    Great plugin by the way and many thanks for your help!

    • This topic was modified 7 years, 5 months ago by lanxalot.
    • This topic was modified 7 years, 5 months ago by lanxalot.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter lanxalot

    (@lanxalot)

    Of course the email form has rendered the code as an apostrophe.

    Silly me! : )

    Just to be clear as to what I am seeing instead of an apostrophe I will paste the code below but leave a space in the middle:

    &# 039;

    Hi lanxalot,

    In the past, when users have had this issue, it’s been a problem with the character encoding of your site or database. One thing to check is what the data inside your database looks like: whether it is stored with the HTML entity (') or the apostrophe.

    Thread Starter lanxalot

    (@lanxalot)

    Hi Nate

    Thanks for the response. I have read a few articles but still don’t know the answer. My hosting provider is looking into it.

    It seems it is definitely connected to the character encoding but I’m unsure if a change needs making to the database or if an instruction needs adding to the website to tell the receiving email client more info about the email content.

    As well as your reservations plugin I also have Contact Form 7. Contact Form 7 had the same issue but I switched the email option to html and this resolved the issue. Just a workaround I know.

    As far as I can see the character set seems to be correct in wp-config.php

    I will paste something I read just now below and see if you think it might be relevant? It involves adding a line into the header. Please see here:

    *****

    header(‘Content-Type: text/html;charset=UTF-8’);

    You need to add the header “Content-Type: text/html; charset=UTF-8” (for HTML Email bodies) or “Content-Type: text/plain; charset=UTF-8” (for Plain Text Email bodies) to your mail function. Like this.

    $headers = array(“Content-Type: text/html; charset=UTF-8”);
    mail($to, $subject, $message, $headers)

    Additionally, for email, each lines should be separated with a CRLF (\r\n) instead of merely using a linefeed (\n). A fully example end result might look more so like this:

    <?php

    $crlf = “\r\n”;

    //Get Data
    $name = strip_tags($_POST[‘name’]);
    $email = strip_tags($_POST[’email’]);
    $service = strip_tags($_POST[‘service’]);
    $phone = strip_tags($_POST[‘phone’]);
    $phoneconfirm = strip_tags($_POST[‘phoneconfirm’]);
    $priority = strip_tags($_POST[‘priority’]);
    $subject = strip_tags($_POST[‘subject’]);
    $message = strip_tags($_POST[‘message’]);

    // Parse/Format/Verify Data
    $to = “[email protected]”;
    $from = ‘[email protected]’;
    $subject = “Via Website”;
    $message = “De: $name$crlf E-Mail: $email$crlf Servi?o: $service$crlf
    Telefone/Celular: $phone$crlf Ligar/Retornar: $phoneconfirm$crlf
    Prioridade: $priority$crlf Assunto: $subject$crlf Mensagem:$crlf
    $message”;

    // Setup EMAIL headers, particularly to support UTF-8
    // We set the EMAIL headers here, these will be sent out with your message
    // for the receiving email client to use.
    $headers = ‘From: ‘ . $from . $crlf .
    ‘Reply-To: ‘ . $from . $crlf .
    ‘Content-Type: text/plain; charset=UTF-8’ . $crlf .
    ‘Para: WebSite’ . $crlf .
    ‘X-Mailer: PHP/’ . phpversion();

    // Then we pass the headers into our mail function
    mail($to, $subject, $message, $headers);
    ?>

    *****

    Do you think there is anything we can add that will help the email client render the special characters correctly?

    I will continue to try and find a solution. It’s frustrating as I really like the plugin but can’t use it until I fix the issue.

    Best regards and thanks for your help!

    • This reply was modified 7 years, 5 months ago by lanxalot.
    Thread Starter lanxalot

    (@lanxalot)

    Hello

    I managed to run a search on all of my databases and replaced

    Stag& #039;s Head Inn (without a space after the &)
    with
    Stag's Head Inn

    This has had the desired effect of making my email headers and subject lines display correctly.

    I have no idea if there are any other problems in the database but the site appears to be working fine so I am happy to leave it as is for now.

    Thanks for your help and for the great plugin!

    Hi @lanxalot,

    Great! I’m glad you were able to get the problem fixed. My plugin does set the HTML/utf-8 headers in the email, as you can see in this line of the code:

    https://github.com/NateWr/restaurant-reservations/blob/master/includes/Notification.Email.class.php#L158

    If you need to add or modify the headers in any way in the future, you can use the rtb_notification_email_headers filter which is located a few lines down from there.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘&# 039; showing instead of apostrophe in emails’ is closed to new replies.