chathura
chathura

Reputation: 3452

How to get rid of spaces in email body - php sending mail

I am trying to implement send email function using php. It is working fine. But the problem when I open the email in inbox it has a lot of spaces in front of message. Is there any way to get rid of these spaces.

Do I need to add additional headers for this.

code:

$to = $email;
$from = "[email protected]";
$subject = "Registration confirmation";
$msg = "message goes here";
$mail = new EMAIL();
$arr = $mail->sendEmail($to,$from,$subject,trim($msg));

Thanks.

Upvotes: 0

Views: 640

Answers (2)

user2533777
user2533777

Reputation:

Try this:

$to = $email;
$from = "[email protected]";
$subject = "Registration confirmation";
$msg = "message goes here";
$mail = new EMAIL();
$arr = $mail->sendEmail($to,$from,$subject,trim(preg_replace('/\s+/',' ', $msg));

This will remove extra spaces, as well as leading and trailing spaces.

Upvotes: 0

ray1
ray1

Reputation: 4048

Just do this:

<?php

$msg = trim($msg);
$msg = preg_replace('/\s+/', ' ', $msg);

$arr = $mail->sendEmail($to, $from, $subject, $msg);

Upvotes: 2

Related Questions