Я пытаюсь отправить письмо на свой GoDaddy
адрес электронной почты из контактного поля моего веб-сайта, используя NodeMailer
. Но при его отправке я получаю 500
ошибку net::ERR_EMPTY_RESPONSE
.
Я тоже прошел через некоторые решения из SO
, но, похоже, я пропустил некоторые сеансы или около того. Нужно ли мне изменить мою конфигурацию или что-нибудь, связанное с получением писем в почтовый ящик godaddy? Любые предложения, что здесь нужно сделать.
// ReactForm
class BookAConsultation extends Component{
constructor(props){
super(props);
this.state={
name: '',
phone: '',
email: '',
comment: ''
};
this.handleOnChange = this.handleOnChange.bind(this);
this.handleOnSubmit = this.handleOnSubmit.bind(this);
}
handleOnChange = (e) => {
this.setState({ [e.target.name] : e.target.value });
}
async handleOnSubmit(e) {
e.preventDefault();
const { name, phone, email, comment } = this.state;
const bookConsultation = await axios.post('api/consultation',{
name,
phone,
email,
comment
})
}
render(){
return(
<Container>
<Grid className="book-a-consultation-header">
<Cell col={6} >
<div className="book-a-consultation">
<Form onSubmit ={this.handleOnSubmit}>
<FormGroup>
<div className="row ">
<Label for="name">Name*</Label>
<Input type="text" name="name" id="name" placeholder="Name"
className="mb-3"
onChange={this.handleOnChange}/>
<Label for="phone">Phone Number*</Label>
<Input type="text" name="phone" id="phone" placeholder="Phone Number"
className="mb-3"
onChange={this.handleOnChange}/>
<Label for="email">Email Id*</Label>
<Input type="email" name="email" id="email" placeholder="Email"
className="mb-3"
onChange={this.handleOnChange}/>
<Label for="comment">Additional Comment</Label>
<textarea type="text" name="comment" id="comment" placeholder="Comment"
className="mb-3"
onChange={this.handleOnChange}/>
<Button
color="dark"
style={{marginTop: '2rem'}}
block
>Book Free Consultation</Button>
</div>
</FormGroup>
</Form>
</div>
</Cell>
</Grid>
</Container>
)
}
}
// Сервер. js
app.post('/api/consultation', (req, res) => {
nodemailer.createTestAccount((err, account) => {
const htmlEmail = `
<h3>Contact deatails </h3>
<ul>
<li>Name: ${req.body.name} </li>
<li>Phone: ${req.body.phone} </li>
<li>Email: ${req.body.email} </li>
</ul>
<h3> Message <h3>
<p>${req.body.content}</p>
`
let mailerConfig = {
host: "smtpout.secureserver.net",
secure: true,
secureConnection: false, // TLS requires secureConnection to be false
tls: {
ciphers:'SSLv3'
},
requireTLS:true,
port: 465,
debug: true,
auth: {
user: "hello@testemail.com",
pass: "password"
}
};
let transporter = nodemailer.createTransport(mailerConfig);
let mailOptions = {
from: 'testemail@gmail.com',
to: 'hello@testemail.com',
replyTo: 'testemail@gmail.com',
subject: 'Some Subject',
text: req.body.content,
html: htmlEmail
};
transporter.sendMail(mailOptions, (err, info) => {
if (error) {
console.log('error:', err);
} else {
console.log('Message sent: %s', info.content);
console.log('Message URL: %s', nodemailer.getTestMessageUrl);
}
});
})
})
// ошибка
![enter image description here](https://i.stack.imgur.com/ltrLv.png)